Skip to content

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

Merged
merged 3 commits into from
Sep 28, 2023

Conversation

sobolevn
Copy link
Member

@sobolevn sobolevn commented Sep 27, 2023

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 serhiy-storchaka and hugovk 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 gh-109961: Docs: Fix incorrect rendering of __replace__ in copy.rst Sep 27, 2023
@AA-Turner
Copy link
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
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
Copy link
Member

AlexWaygood commented Sep 27, 2023

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.

Copy link
Member

@serhiy-storchaka serhiy-storchaka left a comment

Choose a reason for hiding this comment

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

LGTM.

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
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
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__

Copy link
Member Author

@sobolevn sobolevn Sep 27, 2023

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



.. 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__`.
Copy link
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
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
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
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
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
Copy link
Member

hugovk commented Sep 28, 2023

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

@AA-Turner
Copy link
Member

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

A

@sobolevn
Copy link
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
Copy link
Member

hugovk commented Feb 20, 2025

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 <[email protected]>
@bedevere-app
Copy link

bedevere-app bot commented Mar 6, 2025

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 <[email protected]>
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
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants