- 
          
 - 
                Notifications
    
You must be signed in to change notification settings  - Fork 33.3k
 
Closed
Labels
docsDocumentation in the Doc dirDocumentation in the Doc dirtopic-typingtype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error
Description
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__, butobjectdoes not have this method - it can be very confusing - Add some protocol, like 
typing.SupportsReplaceand documentSupportsReplace.__replace__ 
I personally think that typing.SupportsReplace is very useful on its own, because:
- we will use it in 
typeshedfor typingcopy.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
NeilGirdhar
Metadata
Metadata
Assignees
Labels
docsDocumentation in the Doc dirDocumentation in the Doc dirtopic-typingtype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error