We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
copy.replace
__replace__
1 parent b93847d commit 6ba4ca7Copy full SHA for 6ba4ca7
stdlib/@tests/test_cases/check_copy.py
@@ -2,6 +2,7 @@
2
3
import copy
4
import sys
5
+from typing import Any, Generic, TypeVar
6
from typing_extensions import Self, assert_type
7
8
@@ -19,3 +20,20 @@ def __replace__(self, val: int) -> Self:
19
20
obj = ReplaceableClass(42)
21
cpy = copy.replace(obj, val=23)
22
assert_type(cpy, ReplaceableClass)
23
+
24
25
+_T_co = TypeVar("_T_co", covariant=True)
26
27
28
+class Box(Generic[_T_co]):
29
+ def __init__(self, value: _T_co, /) -> None:
30
+ self.value = value
31
32
+ def __replace__(self, value: Any) -> Box[Any]:
33
+ return Box(value)
34
35
36
+if sys.version_info >= (3, 13):
37
+ box1: Box[int] = Box(42)
38
+ box2 = copy.replace(box1, val="spam")
39
+ assert_type(box2, Box[Any])
0 commit comments