Skip to content

gh-109961: Docs: Fix incorrect rendering of __replace__ in copy.rst - #109968

Merged
hugovk merged 3 commits into
python:mainfrom
sobolevn:issue-109961
Sep 28, 2023
Merged

hugovk merged 3 commits into
python:mainfrom
sobolevn:issue-109961

Conversation

@sobolevn

@sobolevn sobolevn commented Sep 27, 2023 •

Copy link
Copy Markdown
Member

This is how it looks now:
Снимок экрана 2023-09-27 в 16 22 12

I've also added __copy__ and __deepcopy__ definitions, so they can be referenced.

Refs #101100


📚 Documentation preview 📚: https://cpython-previews--109968.org.readthedocs.build/

@sobolevn
sobolevn requested review from hugovk and serhiy-storchaka and removed request for serhiy-storchaka September 27, 2023 13:27
@AlexWaygood AlexWaygood changed the title gh-109961: Fix incorrect rendering of __replace__ in library/copyrst Sep 27, 2023
@AA-Turner

Copy link
Copy Markdown
Member

I think we could consider adding these to the datamodel and moving out of copy, I don't know what you'd think?

A

@AA-Turner AA-Turner added needs backport to 3.11 only security fixes needs backport to 3.12 only security fixes labels Sep 27, 2023
@AA-Turner

Copy link
Copy Markdown
Member

The markup changes for copy/deepcopy should be backported; replace should be left out.

A

@AA-Turner AA-Turner added the docs Documentation in the Doc dir label Sep 27, 2023
@AlexWaygood

AlexWaygood commented Sep 27, 2023 •

Copy link
Copy Markdown
Member

I think we could consider adding these to the datamodel and moving out of copy, I don't know what you'd think?

Keeping these methods in the copy docs isn't without precedent: __fspath__ is documented in the os docs; __subclasshook__ is documented in the abc docs. I think there's an argument for keeping them close to the functions they're relevant to.

@serhiy-storchaka serhiy-storchaka left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM.

Comment thread Doc/library/copy.rst
The memo dictionary should be treated as an opaque object.
special methods :meth:`~object.__copy__` and :meth:`~object.__deepcopy__`.

.. method:: object.__copy__(self)

Copy link
Copy Markdown
Member

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.

Copy link
Copy Markdown
Member Author

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 fail nitpick mode:

/Users/sobolev/Desktop/cpython/Doc/library/copy.rst:90: WARNING: py:meth reference target not found: object.__copy__
/Users/sobolev/Desktop/cpython/Doc/library/copy.rst:90: WARNING: py:meth reference target not found: object.__deepcopy__
/Users/sobolev/Desktop/cpython/Doc/library/copy.rst:112: WARNING: py:meth reference target not found: object.__replace__

@sobolevn sobolevn Sep 27, 2023 •

Copy link
Copy Markdown
Member Author

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:
Снимок экрана 2023-09-27 в 17 55 22

They link to:

  • copy.html#copy.object.__replace__
  • copy.html#index-2

Do we need the index directive itself now?

Copy link
Copy Markdown
Member

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

Copy link
Copy Markdown
Member Author

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 :)

Comment thread Doc/library/copy.rst
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__`.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The 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.
I just hope it’s not indexed as copy.object instead of builtins.object!

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Of 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.

@hugovk
hugovk merged commit 0baf726 into python:main Sep 28, 2023
@miss-islington

Copy link
Copy Markdown
Contributor

Thanks @sobolevn for the PR, and @hugovk for merging it 🌮🎉.. I'm working now to backport this PR to: 3.11, 3.12.
🐍🍒⛏🤖

@miss-islington

Copy link
Copy Markdown
Contributor

Sorry, @sobolevn and @hugovk, I could not cleanly backport this to 3.12 due to a conflict.
Please backport using cherry_picker on command line.
cherry_picker 0baf72696e79191241a2d5cfdfd7e6135115f7b2 3.12

@miss-islington

Copy link
Copy Markdown
Contributor

Sorry, @sobolevn and @hugovk, I could not cleanly backport this to 3.11 due to a conflict.
Please backport using cherry_picker on command line.
cherry_picker 0baf72696e79191241a2d5cfdfd7e6135115f7b2 3.11

@hugovk

hugovk commented Sep 28, 2023

Copy link
Copy Markdown
Member

@sobolevn Please could you do the backports? Thank you!

@AA-Turner

Copy link
Copy Markdown
Member

I think this needs a follow-up PR for Serhiy's note: #109968 (comment)

A

@sobolevn

Copy link
Copy Markdown
Member Author

Will do both :)

csm10495 pushed a commit to csm10495/cpython that referenced this pull request Sep 29, 2023
Glyphack pushed a commit to Glyphack/cpython that referenced this pull request Sep 2, 2024
@ZeroIntensity ZeroIntensity removed the needs backport to 3.11 only security fixes label Feb 17, 2025
@hugovk

hugovk commented Feb 20, 2025

Copy link
Copy Markdown
Member

Will do both :)

@sobolevn Still needed? If not, let's remove the backport label.

hugovk pushed a commit to hugovk/cpython that referenced this pull request Mar 6, 2025
…` in `copy.rst` (pythonGH-109968)

(cherry picked from commit 0baf726)

Co-authored-by: Nikita Sobolev <mail@sobolevn.me>
@bedevere-app

bedevere-app Bot commented Mar 6, 2025

Copy link
Copy Markdown

GH-130909 is a backport of this pull request to the 3.12 branch.

@bedevere-app bedevere-app Bot removed the needs backport to 3.12 only security fixes label Mar 6, 2025
hugovk added a commit that referenced this pull request Mar 17, 2025
…copy.rst` (GH-109968) (#130909)

(cherry picked from commit 0baf726)

Co-authored-by: Nikita Sobolev <mail@sobolevn.me>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

docs Documentation in the Doc dir skip news

8 participants