Describe the bug
mypy thinks [1] also fits SequenceNotStr[str].
Since SequenceNotStr is our own definition, I think it worths to discuss here first, before sending the report to mypy.
To Reproduce
Minimal example
from collections.abc import Iterator, Sequence
from typing import Any, Protocol, SupportsIndex, overload
from typing_extensions import reveal_type, TypeVar
_T_co = TypeVar("_T_co", covariant=True)
class SequenceNotStr(Protocol[_T_co]):
@overload
def __getitem__(self, index: SupportsIndex, /) -> _T_co: ...
@overload
def __getitem__(self, index: slice, /) -> Sequence[_T_co]: ...
def __contains__(self, value: object, /) -> bool: ...
def __len__(self) -> int: ...
def __iter__(self) -> Iterator[_T_co]: ...
def index(self, value: Any, start: int = ..., stop: int = ..., /) -> int: ...
def count(self, value: Any, /) -> int: ...
def __reversed__(self) -> Iterator[_T_co]: ...
def foo(a: SequenceNotStr[str]) -> None:
reveal_type(a[0]) # mypy and pyright gives str
reveal_type(foo([1])) # mypy gives None, pyright gives error
Indicate which type checker you are using
both
Please complete the following information:
- OS: Debian
- OS Version: 12
- python version: 3.12
- version of type checker:
mypy 1.19.1
- version of installed
pandas-stubs: None
Additional context
Add any other context about the problem here.
Describe the bug
mypythinks[1]also fitsSequenceNotStr[str].Since
SequenceNotStris our own definition, I think it worths to discuss here first, before sending the report tomypy.To Reproduce
Minimal example
Indicate which type checker you are using
both
Please complete the following information:
mypy1.19.1pandas-stubs: NoneAdditional context
Add any other context about the problem here.