11import sys
22from typing import Any , Protocol , TypeVar , type_check_only
3- from typing_extensions import Self
3+ from typing_extensions import ParamSpec
44
55__all__ = ["Error" , "copy" , "deepcopy" ]
66
77_T = TypeVar ("_T" )
8- _SR = TypeVar ("_SR" , bound = _SupportsReplace )
8+ _Tss = ParamSpec ("_Tss" )
9+ _RT_co = TypeVar ("_RT_co" , covariant = True )
910
1011@type_check_only
11- class _SupportsReplace (Protocol ):
12- # Usually there are *some* kwargs , but there's no great way to express this.
13- def __replace__ (self , / ) -> Self : ...
12+ class _SupportsReplace (Protocol [ _Tss , _RT_co ] ):
13+ # In reality doesn't support args , but there's no other great way to express this.
14+ def __replace__ (self , / , * _ : _Tss . args , ** changes : _Tss . kwargs ) -> _RT_co : ...
1415
1516# None in CPython but non-None in Jython
1617PyStringMap : Any
@@ -21,7 +22,7 @@ def copy(x: _T) -> _T: ...
2122
2223if sys .version_info >= (3 , 13 ):
2324 __all__ += ["replace" ]
24- def replace (obj : _SR , / , ** changes : Any ) -> _SR : ...
25+ def replace (obj : _SupportsReplace [..., _RT_co ], / , ** changes : Any ) -> _RT_co : ...
2526
2627class Error (Exception ): ...
2728
0 commit comments