mirror of
https://github.com/python/cpython.git
synced 2025-08-03 16:39:00 +00:00
gh-101100: Fix various Sphinx warnings for dunder references in the library/
directory (#113163)
This commit is contained in:
parent
c2c4879b0a
commit
1addde0c69
8 changed files with 34 additions and 24 deletions
|
@ -824,8 +824,9 @@ apply to method calls on the mock object.
|
|||
|
||||
.. class:: PropertyMock(*args, **kwargs)
|
||||
|
||||
A mock intended to be used as a property, or other descriptor, on a class.
|
||||
:class:`PropertyMock` provides :meth:`__get__` and :meth:`__set__` methods
|
||||
A mock intended to be used as a :class:`property`, or other
|
||||
:term:`descriptor`, on a class. :class:`PropertyMock` provides
|
||||
:meth:`~object.__get__` and :meth:`~object.__set__` methods
|
||||
so you can specify a return value when it is fetched.
|
||||
|
||||
Fetching a :class:`PropertyMock` instance from an object calls the mock, with
|
||||
|
@ -1707,8 +1708,9 @@ Keywords can be used in the :func:`patch.dict` call to set values in the diction
|
|||
:func:`patch.dict` can be used with dictionary like objects that aren't actually
|
||||
dictionaries. At the very minimum they must support item getting, setting,
|
||||
deleting and either iteration or membership test. This corresponds to the
|
||||
magic methods :meth:`~object.__getitem__`, :meth:`__setitem__`, :meth:`__delitem__` and either
|
||||
:meth:`__iter__` or :meth:`__contains__`.
|
||||
magic methods :meth:`~object.__getitem__`, :meth:`~object.__setitem__`,
|
||||
:meth:`~object.__delitem__` and either :meth:`~container.__iter__` or
|
||||
:meth:`~object.__contains__`.
|
||||
|
||||
>>> class Container:
|
||||
... def __init__(self):
|
||||
|
@ -2171,7 +2173,7 @@ For example:
|
|||
>>> object() in mock
|
||||
False
|
||||
|
||||
The two equality methods, :meth:`__eq__` and :meth:`__ne__`, are special.
|
||||
The two equality methods, :meth:`!__eq__` and :meth:`!__ne__`, are special.
|
||||
They do the default equality comparison on identity, using the
|
||||
:attr:`~Mock.side_effect` attribute, unless you change their return value to
|
||||
return something else::
|
||||
|
@ -2521,8 +2523,8 @@ mock_open
|
|||
*read_data* is now reset on each call to the *mock*.
|
||||
|
||||
.. versionchanged:: 3.8
|
||||
Added :meth:`__iter__` to implementation so that iteration (such as in for
|
||||
loops) correctly consumes *read_data*.
|
||||
Added :meth:`~container.__iter__` to implementation so that iteration
|
||||
(such as in for loops) correctly consumes *read_data*.
|
||||
|
||||
Using :func:`open` as a context manager is a great way to ensure your file handles
|
||||
are closed properly and is becoming common::
|
||||
|
@ -2704,7 +2706,7 @@ able to use autospec. On the other hand it is much better to design your
|
|||
objects so that introspection is safe [#]_.
|
||||
|
||||
A more serious problem is that it is common for instance attributes to be
|
||||
created in the :meth:`__init__` method and not to exist on the class at all.
|
||||
created in the :meth:`~object.__init__` method and not to exist on the class at all.
|
||||
*autospec* can't know about any dynamically created attributes and restricts
|
||||
the api to visible attributes. ::
|
||||
|
||||
|
@ -2745,8 +2747,9 @@ this particular scenario:
|
|||
AttributeError: Mock object has no attribute 'a'
|
||||
|
||||
Probably the best way of solving the problem is to add class attributes as
|
||||
default values for instance members initialised in :meth:`__init__`. Note that if
|
||||
you are only setting default attributes in :meth:`__init__` then providing them via
|
||||
default values for instance members initialised in :meth:`~object.__init__`.
|
||||
Note that if
|
||||
you are only setting default attributes in :meth:`!__init__` then providing them via
|
||||
class attributes (shared between instances of course) is faster too. e.g.
|
||||
|
||||
.. code-block:: python
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue