Skip to content

Commit 68f05dd

Browse files
[3.12] gh-101100: Fix many easily solvable Sphinx nitpicks in the datamodel docs (GH-112737) (#112748)
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 f1a0c77 commit 68f05dd

File tree

2 files changed

+37
-29
lines changed

2 files changed

+37
-29
lines changed

Doc/library/exceptions.rst

+5-3
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

+32-26
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

@@ -681,8 +681,8 @@ underlying the class method.
681681
When an instance method object is called, the underlying function
682682
(:attr:`__func__`) is called, inserting the class instance
683683
(:attr:`__self__`) in front of the argument list. For instance, when
684-
:class:`C` is a class which contains a definition for a function
685-
:meth:`f`, and ``x`` is an instance of :class:`C`, calling ``x.f(1)`` is
684+
:class:`!C` is a class which contains a definition for a function
685+
:meth:`!f`, and ``x`` is an instance of :class:`!C`, calling ``x.f(1)`` is
686686
equivalent to calling ``C.f(x, 1)``.
687687

688688
When an instance method object is derived from a class method object, the
@@ -795,7 +795,7 @@ Classes
795795
Classes are callable. These objects normally act as factories for new
796796
instances of themselves, but variations are possible for class types that
797797
override :meth:`~object.__new__`. The arguments of the call are passed to
798-
:meth:`__new__` and, in the typical case, to :meth:`~object.__init__` to
798+
:meth:`!__new__` and, in the typical case, to :meth:`~object.__init__` to
799799
initialize the new instance.
800800

801801

@@ -899,9 +899,9 @@ https://www.python.org/download/releases/2.3/mro/.
899899
pair: object; dictionary
900900
pair: class; attribute
901901

902-
When a class attribute reference (for class :class:`C`, say) would yield a
902+
When a class attribute reference (for class :class:`!C`, say) would yield a
903903
class method object, it is transformed into an instance method object whose
904-
:attr:`__self__` attribute is :class:`C`. When it would yield a static
904+
:attr:`__self__` attribute is :class:`!C`. When it would yield a static
905905
method object, it is transformed into the object wrapped by the static method
906906
object. See section :ref:`descriptors` for another way in which attributes
907907
retrieved from a class may differ from those actually contained in its
@@ -1898,13 +1898,17 @@ class' :attr:`~object.__dict__`.
18981898

18991899
Called to delete the attribute on an instance *instance* of the owner class.
19001900

1901+
Instances of descriptors may also have the :attr:`!__objclass__` attribute
1902+
present:
19011903

1902-
The attribute :attr:`__objclass__` is interpreted by the :mod:`inspect` module
1903-
as specifying the class where this object was defined (setting this
1904-
appropriately can assist in runtime introspection of dynamic class attributes).
1905-
For callables, it may indicate that an instance of the given type (or a
1906-
subclass) is expected or required as the first positional argument (for example,
1907-
CPython sets this attribute for unbound methods that are implemented in C).
1904+
.. attribute:: object.__objclass__
1905+
1906+
The attribute :attr:`!__objclass__` is interpreted by the :mod:`inspect` module
1907+
as specifying the class where this object was defined (setting this
1908+
appropriately can assist in runtime introspection of dynamic class attributes).
1909+
For callables, it may indicate that an instance of the given type (or a
1910+
subclass) is expected or required as the first positional argument (for example,
1911+
CPython sets this attribute for unbound methods that are implemented in C).
19081912

19091913

19101914
.. _descriptor-invocation:
@@ -1985,13 +1989,14 @@ For instance bindings, the precedence of descriptor invocation depends on
19851989
which descriptor methods are defined. A descriptor can define any combination
19861990
of :meth:`~object.__get__`, :meth:`~object.__set__` and
19871991
:meth:`~object.__delete__`. If it does not
1988-
define :meth:`__get__`, then accessing the attribute will return the descriptor
1992+
define :meth:`!__get__`, then accessing the attribute will return the descriptor
19891993
object itself unless there is a value in the object's instance dictionary. If
1990-
the descriptor defines :meth:`__set__` and/or :meth:`__delete__`, it is a data
1994+
the descriptor defines :meth:`!__set__` and/or :meth:`!__delete__`, it is a data
19911995
descriptor; if it defines neither, it is a non-data descriptor. Normally, data
1992-
descriptors define both :meth:`__get__` and :meth:`__set__`, while non-data
1993-
descriptors have just the :meth:`__get__` method. Data descriptors with
1994-
:meth:`__get__` and :meth:`__set__` (and/or :meth:`__delete__`) defined always override a redefinition in an
1996+
descriptors define both :meth:`!__get__` and :meth:`!__set__`, while non-data
1997+
descriptors have just the :meth:`!__get__` method. Data descriptors with
1998+
:meth:`!__get__` and :meth:`!__set__` (and/or :meth:`!__delete__`) defined
1999+
always override a redefinition in an
19952000
instance dictionary. In contrast, non-data descriptors can be overridden by
19962001
instances.
19972002

@@ -2568,16 +2573,17 @@ either to emulate a sequence or to emulate a mapping; the difference is that for
25682573
a sequence, the allowable keys should be the integers *k* for which ``0 <= k <
25692574
N`` where *N* is the length of the sequence, or :class:`slice` objects, which define a
25702575
range of items. It is also recommended that mappings provide the methods
2571-
:meth:`keys`, :meth:`values`, :meth:`items`, :meth:`get`, :meth:`clear`,
2572-
:meth:`setdefault`, :meth:`pop`, :meth:`popitem`, :meth:`!copy`, and
2573-
:meth:`update` behaving similar to those for Python's standard :class:`dictionary <dict>`
2576+
:meth:`!keys`, :meth:`!values`, :meth:`!items`, :meth:`!get`, :meth:`!clear`,
2577+
:meth:`!setdefault`, :meth:`!pop`, :meth:`!popitem`, :meth:`!copy`, and
2578+
:meth:`!update` behaving similar to those for Python's standard :class:`dictionary <dict>`
25742579
objects. The :mod:`collections.abc` module provides a
25752580
:class:`~collections.abc.MutableMapping`
25762581
:term:`abstract base class` to help create those methods from a base set of
2577-
:meth:`~object.__getitem__`, :meth:`~object.__setitem__`, :meth:`~object.__delitem__`, and :meth:`keys`.
2578-
Mutable sequences should provide methods :meth:`append`, :meth:`count`,
2579-
:meth:`index`, :meth:`extend`, :meth:`insert`, :meth:`pop`, :meth:`remove`,
2580-
:meth:`reverse` and :meth:`sort`, like Python standard :class:`list`
2582+
:meth:`~object.__getitem__`, :meth:`~object.__setitem__`,
2583+
:meth:`~object.__delitem__`, and :meth:`!keys`.
2584+
Mutable sequences should provide methods :meth:`!append`, :meth:`!count`,
2585+
:meth:`!index`, :meth:`!extend`, :meth:`!insert`, :meth:`!pop`, :meth:`!remove`,
2586+
:meth:`!reverse` and :meth:`!sort`, like Python standard :class:`list`
25812587
objects. Finally,
25822588
sequence types should implement addition (meaning concatenation) and
25832589
multiplication (meaning repetition) by defining the methods
@@ -2590,7 +2596,7 @@ operator; for
25902596
mappings, ``in`` should search the mapping's keys; for sequences, it should
25912597
search through the values. It is further recommended that both mappings and
25922598
sequences implement the :meth:`~object.__iter__` method to allow efficient iteration
2593-
through the container; for mappings, :meth:`__iter__` should iterate
2599+
through the container; for mappings, :meth:`!__iter__` should iterate
25942600
through the object's keys; for sequences, it should iterate through the values.
25952601

25962602
.. method:: object.__len__(self)
@@ -3169,7 +3175,7 @@ generators, coroutines do not directly support iteration.
31693175
to the :meth:`~generator.send` method of the iterator that caused
31703176
the coroutine to suspend. The result (return value,
31713177
:exc:`StopIteration`, or other exception) is the same as when
3172-
iterating over the :meth:`__await__` return value, described above.
3178+
iterating over the :meth:`!__await__` return value, described above.
31733179

31743180
.. method:: coroutine.throw(value)
31753181
coroutine.throw(type[, value[, traceback]])

0 commit comments

Comments
 (0)