Skip to content

gh-134559: Expand and reorganise documentation for the copy module #134695

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

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

ferdnyc
Copy link
Contributor

@ferdnyc ferdnyc commented May 26, 2025

The documentation for the copy module was showing its age. Reorganize with additional headings and more uniform structure.

Fixes: #134559

ferdnyc added 2 commits May 26, 2025 04:20
The documentation for the copy module was showing its age.
Reorganize with additional headings and more uniform structure.

Fixes: python#134559
Comment on lines +36 to +37
The difference between shallow and deep copying is only relevant for compound
objects (objects that contain other objects, like lists or class instances):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

'container' is more commonly used and the name of a collections ABC

Suggested change
The difference between shallow and deep copying is only relevant for compound
objects (objects that contain other objects, like lists or class instances):
The difference between shallow and deep copying is only relevant for container
objects; those that contain other objects, like lists or class instances:

Comment on lines +117 to +118
``replace``
-----------
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
``replace``
-----------
:func:`!replace()`
------------------

Comment on lines +125 to +129
Function :func:`!copy.replace` is more limited
than :func:`~copy.copy` and :func:`~copy.deepcopy`,
and only supports named tuples created by :func:`~collections.namedtuple`,
:mod:`dataclasses`, and other classes which implement the replace protocol
(i.e. define a method :meth:`~object.__replace__`).
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Function :func:`!copy.replace` is more limited
than :func:`~copy.copy` and :func:`~copy.deepcopy`,
and only supports named tuples created by :func:`~collections.namedtuple`,
:mod:`dataclasses`, and other classes which implement the replace protocol
(i.e. define a method :meth:`~object.__replace__`).
The :func:`!replace` function is more limited than
:func:`~copy.copy` and :func:`~copy.deepcopy`.
For example, it only supports named tuples created by :func:`~collections.namedtuple`,
:mod:`dataclasses`, and other classes which implement the replace protocol
(i.e. those defining a :meth:`~object.__replace__` method).

@AA-Turner AA-Turner changed the title gh-134559: Expand, reorganize copy module docs gh-134559: Expand and reorganise documentation for the copy module May 26, 2025
Comment on lines +19 to +20
``copy`` and ``deepcopy``
-------------------------
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
``copy`` and ``deepcopy``
-------------------------
:func:`!copy()` and :func:`!deepcopy()`
---------------------------------------

than :func:`~copy.copy` and :func:`~copy.deepcopy`,
and only supports named tuples created by :func:`~collections.namedtuple`,
:mod:`dataclasses`, and other classes which implement the replace protocol
(i.e. define a method :meth:`~object.__replace__`).
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
(i.e. define a method :meth:`~object.__replace__`).
(that is, those defining a :meth:`~object.__replace__` method).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
awaiting review docs Documentation in the Doc dir needs backport to 3.13 bugs and security fixes needs backport to 3.14 bugs and security fixes skip news
Projects
Status: Todo
Development

Successfully merging this pull request may close these issues.

Improve documentation for the copy module
3 participants