Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions stdlib/@tests/test_cases/builtins/check_list.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,12 @@ def asd(self) -> int:
assert_type(combined, List[Union[Foo, Bar]])
for item in combined:
assert_type(item.asd(), int)


def test_list_signature_overlapping_type(l: list[int], key: float) -> None:
# list.{index, count, remove} allow any type for the key since
# (a) the key may overlap with the list's element type, and
# (b) these methods are equality-based anyway.
l.index(key)
l.count(key)
l.remove(key)
6 changes: 3 additions & 3 deletions stdlib/builtins.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -1128,10 +1128,10 @@ class list(MutableSequence[_T]):
def pop(self, index: SupportsIndex = -1, /) -> _T: ...
# Signature of `list.index` should be kept in line with `collections.UserList.index()`
# and multiprocessing.managers.ListProxy.index()
def index(self, value: _T, start: SupportsIndex = 0, stop: SupportsIndex = sys.maxsize, /) -> int: ...
def count(self, value: _T, /) -> int: ...
def index(self, value: object, start: SupportsIndex = 0, stop: SupportsIndex = sys.maxsize, /) -> int: ...
def count(self, value: object, /) -> int: ...
def insert(self, index: SupportsIndex, object: _T, /) -> None: ...
def remove(self, value: _T, /) -> None: ...
def remove(self, value: object, /) -> None: ...
# Signature of `list.sort` should be kept inline with `collections.UserList.sort()`
# and multiprocessing.managers.ListProxy.sort()
#
Expand Down
4 changes: 2 additions & 2 deletions stubs/boltons/boltons/listutils.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ class BarrelList(list[_T]):
def __setslice__(self, start: SupportsIndex, stop: SupportsIndex, sequence: Iterable[_T]) -> None: ...
def sort(self) -> None: ... # type: ignore[override]
def reverse(self) -> None: ...
def count(self, item: _T) -> int: ...
def index(self, item: _T) -> int: ... # type: ignore[override]
def count(self, item: object) -> int: ...
def index(self, item: object) -> int: ... # type: ignore[override]

BList: TypeAlias = BarrelList[_T]

Expand Down