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
1 parent 51685bf commit 9d38af3Copy full SHA for 9d38af3
stdlib/@tests/test_cases/check_copy.py
@@ -10,7 +10,7 @@ class ReplaceableClass:
10
def __init__(self, val: int) -> None:
11
self.val = val
12
13
- def __replace__(self, val: int) -> Self:
+ def __replace__(self, /, *, val: int) -> Self:
14
cpy = copy.copy(self)
15
cpy.val = val
16
return cpy
@@ -29,11 +29,11 @@ class Box(Generic[_T_co]):
29
def __init__(self, value: _T_co, /) -> None:
30
self.value = value
31
32
- def __replace__(self, value: str) -> Box[str]:
+ def __replace__(self, /, *, value: str) -> Box[str]:
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")
+ box2 = copy.replace(box1, value="spam")
39
assert_type(box2, Box[str])
0 commit comments