mirror of
https://github.com/davidhalter/typeshed.git
synced 2025-12-10 05:51:52 +08:00
Add copy.replace for 3.13 (#12262)
This commit is contained in:
21
stdlib/@tests/test_cases/check_copy.py
Normal file
21
stdlib/@tests/test_cases/check_copy.py
Normal file
@@ -0,0 +1,21 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import copy
|
||||
import sys
|
||||
from typing_extensions import Self, assert_type
|
||||
|
||||
|
||||
class ReplaceableClass:
|
||||
def __init__(self, val: int) -> None:
|
||||
self.val = val
|
||||
|
||||
def __replace__(self, val: int) -> Self:
|
||||
cpy = copy.copy(self)
|
||||
cpy.val = val
|
||||
return cpy
|
||||
|
||||
|
||||
if sys.version_info >= (3, 13):
|
||||
obj = ReplaceableClass(42)
|
||||
cpy = copy.replace(obj, val=23)
|
||||
assert_type(cpy, ReplaceableClass)
|
||||
Reference in New Issue
Block a user