Skip to content

Commit d354ddd

Browse files
sobolevnGlyphack
authored andcommitted
pythongh-109961: Docs: Fix incorrect rendering of __replace__ in copy.rst (python#109968)
1 parent a359ff6 commit d354ddd

File tree

2 files changed

+21
-13
lines changed

2 files changed

+21
-13
lines changed

Doc/library/copy.rst

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -88,27 +88,36 @@ pickle functions from the :mod:`copyreg` module.
8888
single: __deepcopy__() (copy protocol)
8989

9090
In order for a class to define its own copy implementation, it can define
91-
special methods :meth:`__copy__` and :meth:`__deepcopy__`. The former is called
92-
to implement the shallow copy operation; no additional arguments are passed.
93-
The latter is called to implement the deep copy operation; it is passed one
94-
argument, the ``memo`` dictionary. If the :meth:`__deepcopy__` implementation needs
95-
to make a deep copy of a component, it should call the :func:`deepcopy` function
96-
with the component as first argument and the memo dictionary as second argument.
97-
The memo dictionary should be treated as an opaque object.
91+
special methods :meth:`~object.__copy__` and :meth:`~object.__deepcopy__`.
92+
93+
.. method:: object.__copy__(self)
94+
:noindexentry:
95+
96+
Called to implement the shallow copy operation;
97+
no additional arguments are passed.
98+
99+
.. method:: object.__deepcopy__(self, memo)
100+
:noindexentry:
101+
102+
Called to implement the deep copy operation; it is passed one
103+
argument, the *memo* dictionary. If the ``__deepcopy__`` implementation needs
104+
to make a deep copy of a component, it should call the :func:`deepcopy` function
105+
with the component as first argument and the *memo* dictionary as second argument.
106+
The *memo* dictionary should be treated as an opaque object.
98107

99108

100109
.. index::
101110
single: __replace__() (replace protocol)
102111

103112
Function :func:`replace` is more limited than :func:`copy` and :func:`deepcopy`,
104113
and only supports named tuples created by :func:`~collections.namedtuple`,
105-
:mod:`dataclasses`, and other classes which define method :meth:`!__replace__`.
114+
:mod:`dataclasses`, and other classes which define method :meth:`~object.__replace__`.
106115

107-
.. method:: __replace__(self, /, **changes)
108-
:noindex:
116+
.. method:: object.__replace__(self, /, **changes)
117+
:noindexentry:
109118

110-
:meth:`!__replace__` should create a new object of the same type,
111-
replacing fields with values from *changes*.
119+
This method should create a new object of the same type,
120+
replacing fields with values from *changes*.
112121

113122

114123
.. seealso::

Doc/tools/.nitignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,6 @@ Doc/library/collections.rst
4848
Doc/library/concurrent.futures.rst
4949
Doc/library/configparser.rst
5050
Doc/library/contextlib.rst
51-
Doc/library/copy.rst
5251
Doc/library/csv.rst
5352
Doc/library/datetime.rst
5453
Doc/library/dbm.rst

0 commit comments

Comments
 (0)