-
-
Notifications
You must be signed in to change notification settings - Fork 32k
Incorrect rendering of __replace__
method in copy
docs: consider adding copy.SupportsReplace
?
#109961
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
Comments
__replace__
method in copy
docs__replace__
method in copy
docs: consider adding typing.SupportsReplace
?
We should document this in the datamodel, similar to A |
I like the idea of We can take the same approach we do with |
Yes, I agree with from copy import replace, SupportsReplace |
Minor, but perhaps consider A |
__replace__
method in copy
docs: consider adding typing.SupportsReplace
?__replace__
method in copy
docs: consider adding copy.SupportsReplace
?
I think I prefer Nikita's name, which is inline with the |
Fair enough -- the suggestion was in large part as currently it is only the
So it seems consistency is not quite here! I think I sympathise most with your fungability argument, given that this replaces data within the object, not the object itself--though for immutable types the object will be replaced! A |
Yes: objects with the |
Thank you for catching this @sobolevn. I think adding |
Ah, if that's the intention, then adding |
Co-authored-by: Adam Turner <[email protected]>
Can it be closed already? |
…10027) Co-authored-by: Adam Turner <[email protected]>
…` in `copy.rst` (pythonGH-109968) (cherry picked from commit 0baf726) Co-authored-by: Nikita Sobolev <[email protected]>
…copy.rst` (GH-109968) (#130909) (cherry picked from commit 0baf726) Co-authored-by: Nikita Sobolev <[email protected]>
Uh oh!
There was an error while loading. Please reload this page.
Bug report
Here's how it looks right now:

Link: https://docs.python.org/dev/library/copy.html
But, there's no such thing as
copy.__replace__
.There are several options:
object.__replace__
, butobject
does not have this method - it can be very confusingtyping.SupportsReplace
and documentSupportsReplace.__replace__
I personally think that
typing.SupportsReplace
is very useful on its own, because:typeshed
for typingcopy.replace
__replace__
is: a protocolSo, it can something like:
We cannot really type
**kwargs
here. See https://discuss.python.org/t/generalize-replace-function/28511/20 But, we can later apply mypy plugin similar to one we use fordataclasses.replace
: https://github.com/python/mypy/blob/4b66fa9de07828621fee1d53abd533f3903e570a/mypy/plugins/dataclasses.py#L390-L402I would like to work on docs / implementation changes after we discuss all the things and come to an agreement :)
CC @serhiy-storchaka @AlexWaygood
Linked PRs
__replace__
incopy.rst
#109968module
forcopy
method docs #110027__replace__
incopy.rst
(GH-109968) #130909The text was updated successfully, but these errors were encountered: