_typing: mark ImmutableListProtocol method arguemnts as position only

PEP 570 (finalized in Python 3.8) added position only arguments to the
Python language. These are separated from position-or-keyword arguments
by adding `/` between them. I.e., `def func(pos_only: int, /, pos_or_kw:
str)`. Many Python builtins in 3.8 were either changed to position only,
or already were position only as this had always existed in the C API,
but not in Python.

Mypy does not complain about these without more strictness turned on,
but pylance does, by default, complain that a `list[str]` cannot be
assigned to `ImmutableListProtocol[str]` because of the position-only
mismatch.
This commit is contained in:
Dylan Baker authored and Paolo Bonzini committed 2026-07-07 07:29:26 +02:00
1 parent 6a04534897
commit f81fdea2ac
1 file changed
+12 -12
+12 -12
View File
@@ -43,27 +43,27 @@ class ImmutableListProtocol(Protocol[T]):
def __iter__(self) -> typing.Iterator[T]: ...
@typing.overload
def __getitem__(self, index: int) -> T: ...
def __getitem__(self, index: int, /) -> T: ...
@typing.overload
def __getitem__(self, index: slice) -> typing.List[T]: ...
def __getitem__(self, index: slice, /) -> typing.List[T]: ...
def __contains__(self, item: T) -> bool: ...
def __contains__(self, item: T, /) -> bool: ...
def __reversed__(self) -> typing.Iterator[T]: ...
def __len__(self) -> int: ...
def __add__(self, other: typing.List[T]) -> typing.List[T]: ...
def __add__(self, other: typing.List[T], /) -> typing.List[T]: ...
def __eq__(self, other: typing.Any) -> bool: ...
def __ne__(self, other: typing.Any) -> bool: ...
def __le__(self, other: typing.Any) -> bool: ...
def __lt__(self, other: typing.Any) -> bool: ...
def __gt__(self, other: typing.Any) -> bool: ...
def __ge__(self, other: typing.Any) -> bool: ...
def __eq__(self, other: typing.Any, /) -> bool: ...
def __ne__(self, other: typing.Any, /) -> bool: ...
def __le__(self, other: typing.Any, /) -> bool: ...
def __lt__(self, other: typing.Any, /) -> bool: ...
def __gt__(self, other: typing.Any, /) -> bool: ...
def __ge__(self, other: typing.Any, /) -> bool: ...
def count(self, item: T) -> int: ...
def count(self, item: T, /) -> int: ...
def index(self, item: T) -> int: ...
def index(self, item: T, /) -> int: ...
def copy(self) -> typing.List[T]: ...