| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| Expand Up | @@ -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__`. | ||
|
Comment thread
Copy link
Copy Markdown
Member
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. Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low QualityThis answers a question I had: with noindexentry, can we still link to the method.
Sorry, something went wrong.
All reactions
Copy link
Copy Markdown
Member
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. Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low QualityOf course, it is copy.object. https://cpython-previews--109968.org.readthedocs.build/en/109968/library/copy.html#copy.object.__replace__ You need to add .. currentmodule:: . to make it builtin.
Sorry, something went wrong.
All reactions
|
||
|
|
||
| .. 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:: | ||
| Expand Down | ||
| Back | FazBrowse Home | New Git URL |
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.
Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low QualityBut please keep :noindex:. There are already entries for __replace__ etc, and duplicates that refer to the same target are confusing.
Sorry, something went wrong.
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.
Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low QualityHm, when adding noindex it starts to fail nitpick mode:
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
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.
Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low QualityWith two indexes we have:

They link to:
Do we need the index directive itself now?
Sorry, something went wrong.
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.
Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low QualityYou could consider :noindexentry:?
A
Sorry, something went wrong.
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.
Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low QualityIt generated just one link in index.html: copy.html#index-2
No warnings 👍
Thanks, TIL about noindexentry :)
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.