Skip to content

Commit bbc7045

Browse files
[3.11] gh-101100: Fix various Sphinx warnings for dunder references in the library/ directory (GH-113163) (#113184)
Co-authored-by: Alex Waygood <[email protected]>
1 parent 740d5da commit bbc7045

File tree

8 files changed

+34
-24
lines changed

8 files changed

+34
-24
lines changed

Doc/conf.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,7 @@
234234
# Attributes/methods/etc. that definitely should be documented better,
235235
# but are deferred for now:
236236
('py:attr', '__annotations__'),
237+
('py:meth', '__missing__'),
237238
('py:attr', '__wrapped__'),
238239
('py:meth', 'index'), # list.index, tuple.index, etc.
239240
]

Doc/library/datetime.rst

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1968,7 +1968,8 @@ Examples of working with a :class:`.time` object::
19681968
American EST and EDT.
19691969

19701970
Special requirement for pickling: A :class:`tzinfo` subclass must have an
1971-
:meth:`__init__` method that can be called with no arguments, otherwise it can be
1971+
:meth:`~object.__init__` method that can be called with no arguments,
1972+
otherwise it can be
19721973
pickled but possibly not unpickled again. This is a technical requirement that
19731974
may be relaxed in the future.
19741975

Doc/library/exceptions.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1005,9 +1005,9 @@ their subgroups based on the types of the contained exceptions.
10051005
True
10061006

10071007

1008-
Note that :exc:`BaseExceptionGroup` defines :meth:`__new__`, so
1008+
Note that :exc:`BaseExceptionGroup` defines :meth:`~object.__new__`, so
10091009
subclasses that need a different constructor signature need to
1010-
override that rather than :meth:`__init__`. For example, the following
1010+
override that rather than :meth:`~object.__init__`. For example, the following
10111011
defines an exception group subclass which accepts an exit_code and
10121012
and constructs the group's message from it. ::
10131013

Doc/library/test.rst

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1386,7 +1386,8 @@ The :mod:`test.support.os_helper` module provides support for os tests.
13861386

13871387
.. class:: FakePath(path)
13881388

1389-
Simple :term:`path-like object`. It implements the :meth:`__fspath__`
1389+
Simple :term:`path-like object`. It implements the
1390+
:meth:`~os.PathLike.__fspath__`
13901391
method which just returns the *path* argument. If *path* is an exception,
13911392
it will be raised in :meth:`!__fspath__`.
13921393

Doc/library/unittest.mock.rst

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -819,8 +819,9 @@ apply to method calls on the mock object.
819819

820820
.. class:: PropertyMock(*args, **kwargs)
821821

822-
A mock intended to be used as a property, or other descriptor, on a class.
823-
:class:`PropertyMock` provides :meth:`__get__` and :meth:`__set__` methods
822+
A mock intended to be used as a :class:`property`, or other
823+
:term:`descriptor`, on a class. :class:`PropertyMock` provides
824+
:meth:`~object.__get__` and :meth:`~object.__set__` methods
824825
so you can specify a return value when it is fetched.
825826

826827
Fetching a :class:`PropertyMock` instance from an object calls the mock, with
@@ -1656,8 +1657,9 @@ Keywords can be used in the :func:`patch.dict` call to set values in the diction
16561657
:func:`patch.dict` can be used with dictionary like objects that aren't actually
16571658
dictionaries. At the very minimum they must support item getting, setting,
16581659
deleting and either iteration or membership test. This corresponds to the
1659-
magic methods :meth:`~object.__getitem__`, :meth:`__setitem__`, :meth:`__delitem__` and either
1660-
:meth:`__iter__` or :meth:`__contains__`.
1660+
magic methods :meth:`~object.__getitem__`, :meth:`~object.__setitem__`,
1661+
:meth:`~object.__delitem__` and either :meth:`~container.__iter__` or
1662+
:meth:`~object.__contains__`.
16611663

16621664
>>> class Container:
16631665
... def __init__(self):
@@ -2120,7 +2122,7 @@ For example:
21202122
>>> object() in mock
21212123
False
21222124

2123-
The two equality methods, :meth:`__eq__` and :meth:`__ne__`, are special.
2125+
The two equality methods, :meth:`!__eq__` and :meth:`!__ne__`, are special.
21242126
They do the default equality comparison on identity, using the
21252127
:attr:`~Mock.side_effect` attribute, unless you change their return value to
21262128
return something else::
@@ -2470,8 +2472,8 @@ mock_open
24702472
*read_data* is now reset on each call to the *mock*.
24712473

24722474
.. versionchanged:: 3.8
2473-
Added :meth:`__iter__` to implementation so that iteration (such as in for
2474-
loops) correctly consumes *read_data*.
2475+
Added :meth:`~container.__iter__` to implementation so that iteration
2476+
(such as in for loops) correctly consumes *read_data*.
24752477

24762478
Using :func:`open` as a context manager is a great way to ensure your file handles
24772479
are closed properly and is becoming common::
@@ -2653,7 +2655,7 @@ able to use autospec. On the other hand it is much better to design your
26532655
objects so that introspection is safe [#]_.
26542656

26552657
A more serious problem is that it is common for instance attributes to be
2656-
created in the :meth:`__init__` method and not to exist on the class at all.
2658+
created in the :meth:`~object.__init__` method and not to exist on the class at all.
26572659
*autospec* can't know about any dynamically created attributes and restricts
26582660
the api to visible attributes. ::
26592661

@@ -2694,8 +2696,9 @@ this particular scenario:
26942696
AttributeError: Mock object has no attribute 'a'
26952697

26962698
Probably the best way of solving the problem is to add class attributes as
2697-
default values for instance members initialised in :meth:`__init__`. Note that if
2698-
you are only setting default attributes in :meth:`__init__` then providing them via
2699+
default values for instance members initialised in :meth:`~object.__init__`.
2700+
Note that if
2701+
you are only setting default attributes in :meth:`!__init__` then providing them via
26992702
class attributes (shared between instances of course) is faster too. e.g.
27002703

27012704
.. code-block:: python

Doc/library/unittest.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1756,7 +1756,7 @@ Grouping tests
17561756
.. method:: __iter__()
17571757

17581758
Tests grouped by a :class:`TestSuite` are always accessed by iteration.
1759-
Subclasses can lazily provide tests by overriding :meth:`__iter__`. Note
1759+
Subclasses can lazily provide tests by overriding :meth:`!__iter__`. Note
17601760
that this method may be called several times on a single suite (for
17611761
example when counting tests or comparing for equality) so the tests
17621762
returned by repeated iterations before :meth:`TestSuite.run` must be the
@@ -1767,7 +1767,7 @@ Grouping tests
17671767

17681768
.. versionchanged:: 3.2
17691769
In earlier versions the :class:`TestSuite` accessed tests directly rather
1770-
than through iteration, so overriding :meth:`__iter__` wasn't sufficient
1770+
than through iteration, so overriding :meth:`!__iter__` wasn't sufficient
17711771
for providing tests.
17721772

17731773
.. versionchanged:: 3.4

Doc/library/wsgiref.rst

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -201,8 +201,9 @@ manipulation of WSGI response headers using a mapping-like interface.
201201
an empty list.
202202

203203
:class:`Headers` objects support typical mapping operations including
204-
:meth:`~object.__getitem__`, :meth:`get`, :meth:`__setitem__`, :meth:`setdefault`,
205-
:meth:`__delitem__` and :meth:`__contains__`. For each of
204+
:meth:`~object.__getitem__`, :meth:`~dict.get`, :meth:`~object.__setitem__`,
205+
:meth:`~dict.setdefault`,
206+
:meth:`~object.__delitem__` and :meth:`~object.__contains__`. For each of
206207
these methods, the key is the header name (treated case-insensitively), and the
207208
value is the first value associated with that header name. Setting a header
208209
deletes any existing values for that header, then adds a new value at the end of
@@ -520,8 +521,10 @@ input, output, and error streams.
520521
want to subclass this instead of :class:`BaseCGIHandler`.
521522

522523
This class is a subclass of :class:`BaseHandler`. It overrides the
523-
:meth:`__init__`, :meth:`get_stdin`, :meth:`get_stderr`, :meth:`add_cgi_vars`,
524-
:meth:`_write`, and :meth:`_flush` methods to support explicitly setting the
524+
:meth:`!__init__`, :meth:`~BaseHandler.get_stdin`,
525+
:meth:`~BaseHandler.get_stderr`, :meth:`~BaseHandler.add_cgi_vars`,
526+
:meth:`~BaseHandler._write`, and :meth:`~BaseHandler._flush` methods to
527+
support explicitly setting the
525528
environment and streams via the constructor. The supplied environment and
526529
streams are stored in the :attr:`stdin`, :attr:`stdout`, :attr:`stderr`, and
527530
:attr:`environ` attributes.

Doc/library/xmlrpc.client.rst

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -269,8 +269,9 @@ DateTime Objects
269269
Write the XML-RPC encoding of this :class:`DateTime` item to the *out* stream
270270
object.
271271

272-
It also supports certain of Python's built-in operators through rich comparison
273-
and :meth:`__repr__` methods.
272+
It also supports certain of Python's built-in operators through
273+
:meth:`rich comparison <object.__lt__>` and :meth:`~object.__repr__`
274+
methods.
274275

275276
A working example follows. The server code::
276277

@@ -334,8 +335,8 @@ Binary Objects
334335
which was the de facto standard base64 specification when the
335336
XML-RPC spec was written.
336337

337-
It also supports certain of Python's built-in operators through :meth:`__eq__`
338-
and :meth:`__ne__` methods.
338+
It also supports certain of Python's built-in operators through
339+
:meth:`~object.__eq__` and :meth:`~object.__ne__` methods.
339340

340341
Example usage of the binary objects. We're going to transfer an image over
341342
XMLRPC::

0 commit comments

Comments
 (0)