Skip to content

Commit e3f670e

Browse files
authored
gh-101100: Fix most Sphinx nitpicks in the glossary and stdtypes.rst (#112757)
1 parent f8c0198 commit e3f670e

File tree

2 files changed

+41
-32
lines changed

2 files changed

+41
-32
lines changed

Doc/glossary.rst

+26-21
Original file line numberDiff line numberDiff line change
@@ -151,9 +151,9 @@ Glossary
151151
A :term:`file object` able to read and write
152152
:term:`bytes-like objects <bytes-like object>`.
153153
Examples of binary files are files opened in binary mode (``'rb'``,
154-
``'wb'`` or ``'rb+'``), :data:`sys.stdin.buffer`,
155-
:data:`sys.stdout.buffer`, and instances of :class:`io.BytesIO` and
156-
:class:`gzip.GzipFile`.
154+
``'wb'`` or ``'rb+'``), :data:`sys.stdin.buffer <sys.stdin>`,
155+
:data:`sys.stdout.buffer <sys.stdout>`, and instances of
156+
:class:`io.BytesIO` and :class:`gzip.GzipFile`.
157157

158158
See also :term:`text file` for a file object able to read and write
159159
:class:`str` objects.
@@ -304,8 +304,9 @@ Glossary
304304
:ref:`class definitions <class>` for more about decorators.
305305

306306
descriptor
307-
Any object which defines the methods :meth:`__get__`, :meth:`__set__`, or
308-
:meth:`__delete__`. When a class attribute is a descriptor, its special
307+
Any object which defines the methods :meth:`~object.__get__`,
308+
:meth:`~object.__set__`, or :meth:`~object.__delete__`.
309+
When a class attribute is a descriptor, its special
309310
binding behavior is triggered upon attribute lookup. Normally, using
310311
*a.b* to get, set or delete an attribute looks up the object named *b* in
311312
the class dictionary for *a*, but if *b* is a descriptor, the respective
@@ -319,7 +320,8 @@ Glossary
319320

320321
dictionary
321322
An associative array, where arbitrary keys are mapped to values. The
322-
keys can be any object with :meth:`__hash__` and :meth:`__eq__` methods.
323+
keys can be any object with :meth:`~object.__hash__` and
324+
:meth:`~object.__eq__` methods.
323325
Called a hash in Perl.
324326

325327
dictionary comprehension
@@ -383,7 +385,7 @@ Glossary
383385

384386
file object
385387
An object exposing a file-oriented API (with methods such as
386-
:meth:`read()` or :meth:`write()`) to an underlying resource. Depending
388+
:meth:`!read` or :meth:`!write`) to an underlying resource. Depending
387389
on the way it was created, a file object can mediate access to a real
388390
on-disk file or to another type of storage or communication device
389391
(for example standard input/output, in-memory buffers, sockets, pipes,
@@ -559,8 +561,9 @@ Glossary
559561

560562
hashable
561563
An object is *hashable* if it has a hash value which never changes during
562-
its lifetime (it needs a :meth:`__hash__` method), and can be compared to
563-
other objects (it needs an :meth:`__eq__` method). Hashable objects which
564+
its lifetime (it needs a :meth:`~object.__hash__` method), and can be
565+
compared to other objects (it needs an :meth:`~object.__eq__` method).
566+
Hashable objects which
564567
compare equal must have the same hash value.
565568

566569
Hashability makes an object usable as a dictionary key and a set member,
@@ -646,7 +649,8 @@ Glossary
646649
iterables include all sequence types (such as :class:`list`, :class:`str`,
647650
and :class:`tuple`) and some non-sequence types like :class:`dict`,
648651
:term:`file objects <file object>`, and objects of any classes you define
649-
with an :meth:`__iter__` method or with a :meth:`~object.__getitem__` method
652+
with an :meth:`~iterator.__iter__` method or with a
653+
:meth:`~object.__getitem__` method
650654
that implements :term:`sequence` semantics.
651655

652656
Iterables can be
@@ -655,7 +659,7 @@ Glossary
655659
as an argument to the built-in function :func:`iter`, it returns an
656660
iterator for the object. This iterator is good for one pass over the set
657661
of values. When using iterables, it is usually not necessary to call
658-
:func:`iter` or deal with iterator objects yourself. The ``for``
662+
:func:`iter` or deal with iterator objects yourself. The :keyword:`for`
659663
statement does that automatically for you, creating a temporary unnamed
660664
variable to hold the iterator for the duration of the loop. See also
661665
:term:`iterator`, :term:`sequence`, and :term:`generator`.
@@ -666,8 +670,8 @@ Glossary
666670
:func:`next`) return successive items in the stream. When no more data
667671
are available a :exc:`StopIteration` exception is raised instead. At this
668672
point, the iterator object is exhausted and any further calls to its
669-
:meth:`__next__` method just raise :exc:`StopIteration` again. Iterators
670-
are required to have an :meth:`__iter__` method that returns the iterator
673+
:meth:`!__next__` method just raise :exc:`StopIteration` again. Iterators
674+
are required to have an :meth:`~iterator.__iter__` method that returns the iterator
671675
object itself so every iterator is also iterable and may be used in most
672676
places where other iterables are accepted. One notable exception is code
673677
which attempts multiple iteration passes. A container object (such as a
@@ -681,7 +685,7 @@ Glossary
681685
.. impl-detail::
682686

683687
CPython does not consistently apply the requirement that an iterator
684-
define :meth:`__iter__`.
688+
define :meth:`~iterator.__iter__`.
685689

686690
key function
687691
A key function or collation function is a callable that returns a value
@@ -875,7 +879,8 @@ Glossary
875879
Old name for the flavor of classes now used for all class objects. In
876880
earlier Python versions, only new-style classes could use Python's newer,
877881
versatile features like :attr:`~object.__slots__`, descriptors,
878-
properties, :meth:`__getattribute__`, class methods, and static methods.
882+
properties, :meth:`~object.__getattribute__`, class methods, and static
883+
methods.
879884

880885
object
881886
Any data with state (attributes or value) and defined behavior
@@ -955,7 +960,7 @@ Glossary
955960
finders implement.
956961

957962
path entry hook
958-
A callable on the :data:`sys.path_hook` list which returns a :term:`path
963+
A callable on the :data:`sys.path_hooks` list which returns a :term:`path
959964
entry finder` if it knows how to find modules on a specific :term:`path
960965
entry`.
961966

@@ -1089,18 +1094,18 @@ Glossary
10891094
sequence
10901095
An :term:`iterable` which supports efficient element access using integer
10911096
indices via the :meth:`~object.__getitem__` special method and defines a
1092-
:meth:`__len__` method that returns the length of the sequence.
1097+
:meth:`~object.__len__` method that returns the length of the sequence.
10931098
Some built-in sequence types are :class:`list`, :class:`str`,
10941099
:class:`tuple`, and :class:`bytes`. Note that :class:`dict` also
1095-
supports :meth:`~object.__getitem__` and :meth:`__len__`, but is considered a
1100+
supports :meth:`~object.__getitem__` and :meth:`!__len__`, but is considered a
10961101
mapping rather than a sequence because the lookups use arbitrary
10971102
:term:`immutable` keys rather than integers.
10981103

10991104
The :class:`collections.abc.Sequence` abstract base class
11001105
defines a much richer interface that goes beyond just
1101-
:meth:`~object.__getitem__` and :meth:`__len__`, adding :meth:`count`,
1102-
:meth:`index`, :meth:`__contains__`, and
1103-
:meth:`__reversed__`. Types that implement this expanded
1106+
:meth:`~object.__getitem__` and :meth:`~object.__len__`, adding
1107+
:meth:`count`, :meth:`index`, :meth:`~object.__contains__`, and
1108+
:meth:`~object.__reversed__`. Types that implement this expanded
11041109
interface can be registered explicitly using
11051110
:func:`~abc.ABCMeta.register`.
11061111

Doc/library/stdtypes.rst

+15-11
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,8 @@ Any object can be tested for truth value, for use in an :keyword:`if` or
4444
.. index:: single: true
4545

4646
By default, an object is considered true unless its class defines either a
47-
:meth:`~object.__bool__` method that returns ``False`` or a :meth:`__len__` method that
47+
:meth:`~object.__bool__` method that returns ``False`` or a
48+
:meth:`~object.__len__` method that
4849
returns zero, when called with the object. [1]_ Here are most of the built-in
4950
objects considered false:
5051

@@ -197,7 +198,7 @@ exception.
197198

198199
Two more operations with the same syntactic priority, :keyword:`in` and
199200
:keyword:`not in`, are supported by types that are :term:`iterable` or
200-
implement the :meth:`__contains__` method.
201+
implement the :meth:`~object.__contains__` method.
201202

202203
.. _typesnumeric:
203204

@@ -717,7 +718,7 @@ that's defined for any rational number, and hence applies to all instances of
717718
:class:`int` and :class:`fractions.Fraction`, and all finite instances of
718719
:class:`float` and :class:`decimal.Decimal`. Essentially, this function is
719720
given by reduction modulo ``P`` for a fixed prime ``P``. The value of ``P`` is
720-
made available to Python as the :attr:`modulus` attribute of
721+
made available to Python as the :attr:`~sys.hash_info.modulus` attribute of
721722
:data:`sys.hash_info`.
722723

723724
.. impl-detail::
@@ -906,9 +907,9 @@ Generator Types
906907
---------------
907908

908909
Python's :term:`generator`\s provide a convenient way to implement the iterator
909-
protocol. If a container object's :meth:`__iter__` method is implemented as a
910+
protocol. If a container object's :meth:`~iterator.__iter__` method is implemented as a
910911
generator, it will automatically return an iterator object (technically, a
911-
generator object) supplying the :meth:`__iter__` and :meth:`~generator.__next__`
912+
generator object) supplying the :meth:`!__iter__` and :meth:`~generator.__next__`
912913
methods.
913914
More information about generators can be found in :ref:`the documentation for
914915
the yield expression <yieldexpr>`.
@@ -3672,7 +3673,7 @@ The conversion types are:
36723673
+------------+-----------------------------------------------------+-------+
36733674
| ``'b'`` | Bytes (any object that follows the | \(5) |
36743675
| | :ref:`buffer protocol <bufferobjects>` or has | |
3675-
| | :meth:`__bytes__`). | |
3676+
| | :meth:`~object.__bytes__`). | |
36763677
+------------+-----------------------------------------------------+-------+
36773678
| ``'s'`` | ``'s'`` is an alias for ``'b'`` and should only | \(6) |
36783679
| | be used for Python2/3 code bases. | |
@@ -4410,7 +4411,8 @@ The constructors for both classes work the same:
44104411
:meth:`symmetric_difference_update` methods will accept any iterable as an
44114412
argument.
44124413

4413-
Note, the *elem* argument to the :meth:`__contains__`, :meth:`remove`, and
4414+
Note, the *elem* argument to the :meth:`~object.__contains__`,
4415+
:meth:`remove`, and
44144416
:meth:`discard` methods may be a set. To support searching for an equivalent
44154417
frozenset, a temporary one is created from *elem*.
44164418

@@ -5236,9 +5238,11 @@ instantiated from the type::
52365238
TypeError: cannot create 'types.UnionType' instances
52375239

52385240
.. note::
5239-
The :meth:`__or__` method for type objects was added to support the syntax
5240-
``X | Y``. If a metaclass implements :meth:`__or__`, the Union may
5241-
override it::
5241+
The :meth:`!__or__` method for type objects was added to support the syntax
5242+
``X | Y``. If a metaclass implements :meth:`!__or__`, the Union may
5243+
override it:
5244+
5245+
.. doctest::
52425246

52435247
>>> class M(type):
52445248
... def __or__(self, other):
@@ -5250,7 +5254,7 @@ instantiated from the type::
52505254
>>> C | int
52515255
'Hello'
52525256
>>> int | C
5253-
int | __main__.C
5257+
int | C
52545258

52555259
.. seealso::
52565260

0 commit comments

Comments
 (0)