Skip to content

Commit 80c314c

Browse files
[3.11] gh-101100: Fix many easily solvable Sphinx nitpicks in the datamodel docs (GH-112737) (#112749)
gh-101100: Fix many easily solvable Sphinx nitpicks in the datamodel docs (GH-112737) (cherry picked from commit 2f20caf) Co-authored-by: Alex Waygood <[email protected]>
1 parent 8a51f6d commit 80c314c

File tree

2 files changed

+37
-29
lines changed

2 files changed

+37
-29
lines changed

Doc/library/exceptions.rst

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -429,9 +429,11 @@ The following exceptions are the exceptions that are usually raised.
429429
:meth:`~iterator.__next__` method to signal that there are no further
430430
items produced by the iterator.
431431

432-
The exception object has a single attribute :attr:`value`, which is
433-
given as an argument when constructing the exception, and defaults
434-
to :const:`None`.
432+
.. attribute:: StopIteration.value
433+
434+
The exception object has a single attribute :attr:`!value`, which is
435+
given as an argument when constructing the exception, and defaults
436+
to :const:`None`.
435437

436438
When a :term:`generator` or :term:`coroutine` function
437439
returns, a new :exc:`StopIteration` instance is

Doc/reference/datamodel.rst

Lines changed: 32 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ Some objects contain references to "external" resources such as open files or
8888
windows. It is understood that these resources are freed when the object is
8989
garbage-collected, but since garbage collection is not guaranteed to happen,
9090
such objects also provide an explicit way to release the external resource,
91-
usually a :meth:`close` method. Programs are strongly recommended to explicitly
91+
usually a :meth:`!close` method. Programs are strongly recommended to explicitly
9292
close such objects. The ':keyword:`try`...\ :keyword:`finally`' statement
9393
and the ':keyword:`with`' statement provide convenient ways to do this.
9494

@@ -674,8 +674,8 @@ underlying the class method.
674674
When an instance method object is called, the underlying function
675675
(:attr:`__func__`) is called, inserting the class instance
676676
(:attr:`__self__`) in front of the argument list. For instance, when
677-
:class:`C` is a class which contains a definition for a function
678-
:meth:`f`, and ``x`` is an instance of :class:`C`, calling ``x.f(1)`` is
677+
:class:`!C` is a class which contains a definition for a function
678+
:meth:`!f`, and ``x`` is an instance of :class:`!C`, calling ``x.f(1)`` is
679679
equivalent to calling ``C.f(x, 1)``.
680680

681681
When an instance method object is derived from a class method object, the
@@ -788,7 +788,7 @@ Classes
788788
Classes are callable. These objects normally act as factories for new
789789
instances of themselves, but variations are possible for class types that
790790
override :meth:`~object.__new__`. The arguments of the call are passed to
791-
:meth:`__new__` and, in the typical case, to :meth:`~object.__init__` to
791+
:meth:`!__new__` and, in the typical case, to :meth:`~object.__init__` to
792792
initialize the new instance.
793793

794794

@@ -892,9 +892,9 @@ https://www.python.org/download/releases/2.3/mro/.
892892
pair: object; dictionary
893893
pair: class; attribute
894894

895-
When a class attribute reference (for class :class:`C`, say) would yield a
895+
When a class attribute reference (for class :class:`!C`, say) would yield a
896896
class method object, it is transformed into an instance method object whose
897-
:attr:`__self__` attribute is :class:`C`. When it would yield a static
897+
:attr:`__self__` attribute is :class:`!C`. When it would yield a static
898898
method object, it is transformed into the object wrapped by the static method
899899
object. See section :ref:`descriptors` for another way in which attributes
900900
retrieved from a class may differ from those actually contained in its
@@ -1883,13 +1883,17 @@ class' :attr:`~object.__dict__`.
18831883

18841884
Called to delete the attribute on an instance *instance* of the owner class.
18851885

1886+
Instances of descriptors may also have the :attr:`!__objclass__` attribute
1887+
present:
18861888

1887-
The attribute :attr:`__objclass__` is interpreted by the :mod:`inspect` module
1888-
as specifying the class where this object was defined (setting this
1889-
appropriately can assist in runtime introspection of dynamic class attributes).
1890-
For callables, it may indicate that an instance of the given type (or a
1891-
subclass) is expected or required as the first positional argument (for example,
1892-
CPython sets this attribute for unbound methods that are implemented in C).
1889+
.. attribute:: object.__objclass__
1890+
1891+
The attribute :attr:`!__objclass__` is interpreted by the :mod:`inspect` module
1892+
as specifying the class where this object was defined (setting this
1893+
appropriately can assist in runtime introspection of dynamic class attributes).
1894+
For callables, it may indicate that an instance of the given type (or a
1895+
subclass) is expected or required as the first positional argument (for example,
1896+
CPython sets this attribute for unbound methods that are implemented in C).
18931897

18941898

18951899
.. _descriptor-invocation:
@@ -1970,13 +1974,14 @@ For instance bindings, the precedence of descriptor invocation depends on
19701974
which descriptor methods are defined. A descriptor can define any combination
19711975
of :meth:`~object.__get__`, :meth:`~object.__set__` and
19721976
:meth:`~object.__delete__`. If it does not
1973-
define :meth:`__get__`, then accessing the attribute will return the descriptor
1977+
define :meth:`!__get__`, then accessing the attribute will return the descriptor
19741978
object itself unless there is a value in the object's instance dictionary. If
1975-
the descriptor defines :meth:`__set__` and/or :meth:`__delete__`, it is a data
1979+
the descriptor defines :meth:`!__set__` and/or :meth:`!__delete__`, it is a data
19761980
descriptor; if it defines neither, it is a non-data descriptor. Normally, data
1977-
descriptors define both :meth:`__get__` and :meth:`__set__`, while non-data
1978-
descriptors have just the :meth:`__get__` method. Data descriptors with
1979-
:meth:`__get__` and :meth:`__set__` (and/or :meth:`__delete__`) defined always override a redefinition in an
1981+
descriptors define both :meth:`!__get__` and :meth:`!__set__`, while non-data
1982+
descriptors have just the :meth:`!__get__` method. Data descriptors with
1983+
:meth:`!__get__` and :meth:`!__set__` (and/or :meth:`!__delete__`) defined
1984+
always override a redefinition in an
19801985
instance dictionary. In contrast, non-data descriptors can be overridden by
19811986
instances.
19821987

@@ -2549,16 +2554,17 @@ either to emulate a sequence or to emulate a mapping; the difference is that for
25492554
a sequence, the allowable keys should be the integers *k* for which ``0 <= k <
25502555
N`` where *N* is the length of the sequence, or :class:`slice` objects, which define a
25512556
range of items. It is also recommended that mappings provide the methods
2552-
:meth:`keys`, :meth:`values`, :meth:`items`, :meth:`get`, :meth:`clear`,
2553-
:meth:`setdefault`, :meth:`pop`, :meth:`popitem`, :meth:`!copy`, and
2554-
:meth:`update` behaving similar to those for Python's standard :class:`dictionary <dict>`
2557+
:meth:`!keys`, :meth:`!values`, :meth:`!items`, :meth:`!get`, :meth:`!clear`,
2558+
:meth:`!setdefault`, :meth:`!pop`, :meth:`!popitem`, :meth:`!copy`, and
2559+
:meth:`!update` behaving similar to those for Python's standard :class:`dictionary <dict>`
25552560
objects. The :mod:`collections.abc` module provides a
25562561
:class:`~collections.abc.MutableMapping`
25572562
:term:`abstract base class` to help create those methods from a base set of
2558-
:meth:`~object.__getitem__`, :meth:`~object.__setitem__`, :meth:`~object.__delitem__`, and :meth:`keys`.
2559-
Mutable sequences should provide methods :meth:`append`, :meth:`count`,
2560-
:meth:`index`, :meth:`extend`, :meth:`insert`, :meth:`pop`, :meth:`remove`,
2561-
:meth:`reverse` and :meth:`sort`, like Python standard :class:`list`
2563+
:meth:`~object.__getitem__`, :meth:`~object.__setitem__`,
2564+
:meth:`~object.__delitem__`, and :meth:`!keys`.
2565+
Mutable sequences should provide methods :meth:`!append`, :meth:`!count`,
2566+
:meth:`!index`, :meth:`!extend`, :meth:`!insert`, :meth:`!pop`, :meth:`!remove`,
2567+
:meth:`!reverse` and :meth:`!sort`, like Python standard :class:`list`
25622568
objects. Finally,
25632569
sequence types should implement addition (meaning concatenation) and
25642570
multiplication (meaning repetition) by defining the methods
@@ -2571,7 +2577,7 @@ operator; for
25712577
mappings, ``in`` should search the mapping's keys; for sequences, it should
25722578
search through the values. It is further recommended that both mappings and
25732579
sequences implement the :meth:`~object.__iter__` method to allow efficient iteration
2574-
through the container; for mappings, :meth:`__iter__` should iterate
2580+
through the container; for mappings, :meth:`!__iter__` should iterate
25752581
through the object's keys; for sequences, it should iterate through the values.
25762582

25772583
.. method:: object.__len__(self)
@@ -3109,7 +3115,7 @@ generators, coroutines do not directly support iteration.
31093115
to the :meth:`~generator.send` method of the iterator that caused
31103116
the coroutine to suspend. The result (return value,
31113117
:exc:`StopIteration`, or other exception) is the same as when
3112-
iterating over the :meth:`__await__` return value, described above.
3118+
iterating over the :meth:`!__await__` return value, described above.
31133119

31143120
.. method:: coroutine.throw(value)
31153121
coroutine.throw(type[, value[, traceback]])

0 commit comments

Comments
 (0)