From dd1bbb5c271616e22d31ce20ec0d43e674f949e3 Mon Sep 17 00:00:00 2001 From: sobolevn Date: Wed, 27 Sep 2023 16:21:27 +0300 Subject: [PATCH 1/3] gh-109961: Fix incorrect rendering of `__replace__` in `library/copy.rst` --- Doc/library/copy.rst | 30 ++++++++++++++++++------------ Doc/tools/.nitignore | 1 - 2 files changed, 18 insertions(+), 13 deletions(-) diff --git a/Doc/library/copy.rst b/Doc/library/copy.rst index cc4ca034d07a00..4347cbf7983b7d 100644 --- a/Doc/library/copy.rst +++ b/Doc/library/copy.rst @@ -88,13 +88,20 @@ 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) + + Called to implement the shallow copy operation; + no additional arguments are passed. + +.. method:: object.__deepcopy__(self, memo) + + 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 +109,12 @@ 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) -: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:: diff --git a/Doc/tools/.nitignore b/Doc/tools/.nitignore index 1dd7676eab057e..1429c413860ad3 100644 --- a/Doc/tools/.nitignore +++ b/Doc/tools/.nitignore @@ -48,7 +48,6 @@ Doc/library/collections.rst Doc/library/concurrent.futures.rst Doc/library/configparser.rst Doc/library/contextlib.rst -Doc/library/copy.rst Doc/library/csv.rst Doc/library/datetime.rst Doc/library/dbm.rst From 15de5b9e7a5a5063b95691e508bcec0b7fbb6f68 Mon Sep 17 00:00:00 2001 From: sobolevn Date: Wed, 27 Sep 2023 17:48:53 +0300 Subject: [PATCH 2/3] keep noindex --- Doc/library/copy.rst | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Doc/library/copy.rst b/Doc/library/copy.rst index 4347cbf7983b7d..bb90cad3c1bb11 100644 --- a/Doc/library/copy.rst +++ b/Doc/library/copy.rst @@ -91,11 +91,13 @@ In order for a class to define its own copy implementation, it can define special methods :meth:`~object.__copy__` and :meth:`~object.__deepcopy__`. .. method:: object.__copy__(self) + :noindex: Called to implement the shallow copy operation; no additional arguments are passed. .. method:: object.__deepcopy__(self, memo) + :noindex: Called to implement the deep copy operation; it is passed one argument, the *memo* dictionary. If the ``__deepcopy__`` implementation needs @@ -112,6 +114,7 @@ and only supports named tuples created by :func:`~collections.namedtuple`, :mod:`dataclasses`, and other classes which define method :meth:`~object.__replace__`. .. method:: object.__replace__(self, /, **changes) + :noindex: This method should create a new object of the same type, replacing fields with values from *changes*. From e9ea5140d4a500990f341344536ce2d748cd222b Mon Sep 17 00:00:00 2001 From: sobolevn Date: Wed, 27 Sep 2023 18:07:29 +0300 Subject: [PATCH 3/3] Use `:noindexentry:` --- Doc/library/copy.rst | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Doc/library/copy.rst b/Doc/library/copy.rst index bb90cad3c1bb11..811b2c51dd3d52 100644 --- a/Doc/library/copy.rst +++ b/Doc/library/copy.rst @@ -91,13 +91,13 @@ In order for a class to define its own copy implementation, it can define special methods :meth:`~object.__copy__` and :meth:`~object.__deepcopy__`. .. method:: object.__copy__(self) - :noindex: + :noindexentry: Called to implement the shallow copy operation; no additional arguments are passed. .. method:: object.__deepcopy__(self, memo) - :noindex: + :noindexentry: Called to implement the deep copy operation; it is passed one argument, the *memo* dictionary. If the ``__deepcopy__`` implementation needs @@ -114,7 +114,7 @@ and only supports named tuples created by :func:`~collections.namedtuple`, :mod:`dataclasses`, and other classes which define method :meth:`~object.__replace__`. .. method:: object.__replace__(self, /, **changes) - :noindex: + :noindexentry: This method should create a new object of the same type, replacing fields with values from *changes*.