-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Abstract __getitem__ in Sequence doesn't type check #3458
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
I don't think this is specific to # test_case.py
from abc import abstractmethod
from typing import List, Union, overload
class GetItemBase:
@overload
def __getitem__(self, key: int) -> int:
...
@overload
def __getitem__(self, key: slice) -> List[int]:
...
@abstractmethod
def __getitem__(self, key: Union[int, slice]) -> Union[int, List[int]]:
...
class GetItemTest(GetItemBase):
def __getitem__(self, key: Union[int, slice]) -> Union[int, List[int]]: # <- typing error despite being identical
return list(range(10))[key] Runtime:
|
To fix this, you can class GetItemBase:
@overload
def __getitem__(self, key: int) -> int:
...
@overload
def __getitem__(self, key: slice) -> List[int]:
...
@abstractmethod
def __getitem__(self, key: Union[int, slice]) -> Union[int, List[int]]:
...
class GetItemTest(GetItemBase):
@overload
def __getitem__(self, key: int) -> int:
...
@overload
def __getitem__(self, key: slice) -> List[int]:
...
def __getitem__(self, key: Union[int, slice]) -> Union[int, List[int]]: # <- typing error despite being identical
return list(range(10))[key] |
I have the following code snippet
Mypy claims that the signature of the abstract getitem is incompatible with that of the supertype. Can anyone give me a hand with this?
The text was updated successfully, but these errors were encountered: