11import sys
22from typing import Any , Protocol , TypeVar , type_check_only
3- from typing_extensions import Self
43
54__all__ = ["Error" , "copy" , "deepcopy" ]
65
76_T = TypeVar ("_T" )
8- _SR = TypeVar ("_SR " , bound = _SupportsReplace )
7+ _RT_co = TypeVar ("_RT_co " , covariant = True )
98
109@type_check_only
11- class _SupportsReplace (Protocol ):
12- # In reality doesn't support args, but there's no other great way to express this.
13- def __replace__ (self , * args : Any , ** kwargs : Any ) -> Self : ...
10+ class _SupportsReplace (Protocol [ _RT_co ] ):
11+ # In reality doesn't support args, but there's no great way to express this.
12+ def __replace__ (self , / , * _ : Any , ** changes : Any ) -> _RT_co : ...
1413
1514# None in CPython but non-None in Jython
1615PyStringMap : Any
@@ -21,7 +20,8 @@ def copy(x: _T) -> _T: ...
2120
2221if sys .version_info >= (3 , 13 ):
2322 __all__ += ["replace" ]
24- def replace (obj : _SR , / , ** changes : Any ) -> _SR : ...
23+ # The types accepted by `**changes` match those of `obj.__replace__`.
24+ def replace (obj : _SupportsReplace [_RT_co ], / , ** changes : Any ) -> _RT_co : ...
2525
2626class Error (Exception ): ...
2727
0 commit comments