1
1
import sys
2
2
from typing import Any , Protocol , TypeVar , type_check_only
3
- from typing_extensions import Self
4
3
5
4
__all__ = ["Error" , "copy" , "deepcopy" ]
6
5
7
6
_T = TypeVar ("_T" )
8
- _SR = TypeVar ("_SR " , bound = _SupportsReplace )
7
+ _RT_co = TypeVar ("_RT_co " , covariant = True )
9
8
10
9
@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 : ...
14
13
15
14
# None in CPython but non-None in Jython
16
15
PyStringMap : Any
@@ -21,7 +20,8 @@ def copy(x: _T) -> _T: ...
21
20
22
21
if sys .version_info >= (3 , 13 ):
23
22
__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 : ...
25
25
26
26
class Error (Exception ): ...
27
27
0 commit comments