Skip to content

Commit b81d98d

Browse files
committed
fix list.copy to use the expected type
1 parent bf484ab commit b81d98d

File tree

2 files changed

+6
-1
lines changed

2 files changed

+6
-1
lines changed

stdlib/@tests/test_cases/builtins/check_list.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,8 @@ def asd(self) -> int:
1919
assert_type(combined, List[Union[Foo, Bar]])
2020
for item in combined:
2121
assert_type(item.asd(), int)
22+
23+
l1: list[int] = [1]
24+
l2: list[object] = l1.copy()
25+
# this is an error, because a list of ints can't be a list of strs
26+
l3: list[str] = l1.copy() # type: ignore

stdlib/builtins.pyi

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1104,7 +1104,7 @@ class list(MutableSequence[_T]):
11041104
def __init__(self) -> None: ...
11051105
@overload
11061106
def __init__(self, iterable: Iterable[_T], /) -> None: ...
1107-
def copy(self) -> list[_T]: ...
1107+
def copy(self) -> list[_S | _T]: ...
11081108
def append(self, object: _T, /) -> None: ...
11091109
def extend(self, iterable: Iterable[_T], /) -> None: ...
11101110
def pop(self, index: SupportsIndex = -1, /) -> _T: ...

0 commit comments

Comments
 (0)