diff options
author | Nikita Sobolev <mail@sobolevn.me> | 2023-09-28 11:51:33 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-09-28 11:51:33 (GMT) |
commit | 0baf72696e79191241a2d5cfdfd7e6135115f7b2 (patch) | |
tree | c67c6a9523bc92d41d1b4bdb5384a04fe7a46ca9 /Doc/library | |
parent | 8f324b7ecd2df3036fab098c4c8ac185ac07b277 (diff) | |
download | cpython-0baf72696e79191241a2d5cfdfd7e6135115f7b2.zip cpython-0baf72696e79191241a2d5cfdfd7e6135115f7b2.tar.gz cpython-0baf72696e79191241a2d5cfdfd7e6135115f7b2.tar.bz2 |
gh-109961: Docs: Fix incorrect rendering of `__replace__` in `copy.rst` (#109968)
Diffstat (limited to 'Doc/library')
-rw-r--r-- | Doc/library/copy.rst | 33 |
1 files changed, 21 insertions, 12 deletions
diff --git a/Doc/library/copy.rst b/Doc/library/copy.rst index cc4ca03..811b2c5 100644 --- a/Doc/library/copy.rst +++ b/Doc/library/copy.rst @@ -88,13 +88,22 @@ pickle functions from the :mod:`copyreg` module. single: __deepcopy__() (copy protocol) In order for a class to define its own copy implementation, it can define -special methods :meth:`__copy__` and :meth:`__deepcopy__`. The former is called -to implement the shallow copy operation; no additional arguments are passed. -The latter is called to implement the deep copy operation; it is passed one -argument, the ``memo`` dictionary. If the :meth:`__deepcopy__` implementation needs -to make a deep copy of a component, it should call the :func:`deepcopy` function -with the component as first argument and the memo dictionary as second argument. -The memo dictionary should be treated as an opaque object. +special methods :meth:`~object.__copy__` and :meth:`~object.__deepcopy__`. + +.. method:: object.__copy__(self) + :noindexentry: + + Called to implement the shallow copy operation; + no additional arguments are passed. + +.. method:: object.__deepcopy__(self, memo) + :noindexentry: + + Called to implement the deep copy operation; it is passed one + argument, the *memo* dictionary. If the ``__deepcopy__`` implementation needs + to make a deep copy of a component, it should call the :func:`deepcopy` function + with the component as first argument and the *memo* dictionary as second argument. + The *memo* dictionary should be treated as an opaque object. .. index:: @@ -102,13 +111,13 @@ The memo dictionary should be treated as an opaque object. Function :func:`replace` is more limited than :func:`copy` and :func:`deepcopy`, and only supports named tuples created by :func:`~collections.namedtuple`, -:mod:`dataclasses`, and other classes which define method :meth:`!__replace__`. +:mod:`dataclasses`, and other classes which define method :meth:`~object.__replace__`. - .. method:: __replace__(self, /, **changes) - :noindex: +.. method:: object.__replace__(self, /, **changes) + :noindexentry: -:meth:`!__replace__` should create a new object of the same type, -replacing fields with values from *changes*. + This method should create a new object of the same type, + replacing fields with values from *changes*. .. seealso:: |