From f81fdea2ac81299b95cc3668a3180ab6db7ba6d5 Mon Sep 17 00:00:00 2001 From: Dylan Baker Date: Mon, 6 Jul 2026 19:03:40 +0000 Subject: [PATCH] _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. --- mesonbuild/_typing.py | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/mesonbuild/_typing.py b/mesonbuild/_typing.py index 8336c46bd..2777d1983 100644 --- a/mesonbuild/_typing.py +++ b/mesonbuild/_typing.py @@ -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]: ...