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:
- Do not document this as a method (however, it is)
- Document it as
object.__replace__, but object does not have this method - it can be very confusing
- Add some protocol, like
typing.SupportsReplace and document SupportsReplace.__replace__
I personally think that typing.SupportsReplace is very useful on its own, because:
- we will use it in
typeshed for typing copy.replace
- it can be used in other places by end users
- it matches exactly what
__replace__ is: a protocol
So, it can something like:
class SupportsReplace(Protocol):
def __replace__(self, /, **kwargs: Any) -> Self: ...
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 for dataclasses.replace: https://github.com/python/mypy/blob/4b66fa9de07828621fee1d53abd533f3903e570a/mypy/plugins/dataclasses.py#L390-L402
I 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
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__, butobjectdoes not have this method - it can be very confusingtyping.SupportsReplaceand documentSupportsReplace.__replace__I personally think that
typing.SupportsReplaceis very useful on its own, because:typeshedfor typingcopy.replace__replace__is: a protocolSo, it can something like:
We cannot really type
**kwargshere. 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#109968moduleforcopymethod docs #110027__replace__incopy.rst(GH-109968) #130909