-
-
Notifications
You must be signed in to change notification settings - Fork 32.1k
gh-109961: Docs: Fix incorrect rendering of __replace__
in copy.rst
#109968
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -88,27 +88,36 @@ 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:: | ||
single: __replace__() (replace protocol) | ||
|
||
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__`. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This answers a question I had: with noindexentry, can we still link to the method. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Of course, it is You need to add |
||
|
||
.. 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:: | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But please keep
:noindex:
. There are already entries for__replace__
etc, and duplicates that refer to the same target are confusing.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hm, when adding
noindex
it starts to failnitpick
mode:Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
With two indexes we have:

They link to:
copy.html#copy.object.__replace__
copy.html#index-2
Do we need the
index
directive itself now?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You could consider
:noindexentry:
?A
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It generated just one link in
index.html
:copy.html#index-2
No warnings 👍
Thanks, TIL about
noindexentry
:)