Skip to content

Commit b93847d

Browse files
committed
support for asymmetric __replace__ in copy.replace
1 parent 0403f9d commit b93847d

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

stdlib/copy.pyi

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,17 @@
11
import sys
22
from 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
1617
PyStringMap: Any
@@ -21,7 +22,7 @@ def copy(x: _T) -> _T: ...
2122

2223
if 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

2627
class Error(Exception): ...
2728

0 commit comments

Comments
 (0)