Skip to content
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

Subclass of Generic containing Any doesn't work with TypeVar #11949

Closed
Dreamsorcerer opened this issue Jan 9, 2022 · 1 comment
Closed

Subclass of Generic containing Any doesn't work with TypeVar #11949

Dreamsorcerer opened this issue Jan 9, 2022 · 1 comment
Labels
bug mypy got something wrong

Comments

@Dreamsorcerer
Copy link
Contributor

I'm not sure if this is a bug, or I'm just misunderstanding it. But, any tips on how to make it pass correctly would be great.

class Application(MutableMapping[Union[str, AppKey[Any]], Any]):
    @overload
    def __getitem__(self, key: AppKey[_T]) -> _T: ...
    @overload
    def __getitem__(self, key: str) -> Any: ...
    def __getitem__(self, key: Union[str, AppKey[_T]]) -> Any:
        return self._state[key]

Outputs:

aiohttp/web_app.py:145: error: Signature of "__getitem__" incompatible with supertype "Mapping"  [override]
aiohttp/web_app.py:145: note:      Superclass:
aiohttp/web_app.py:145: note:          def __getitem__(self, Union[str, AppKey[Any]]) -> Any
aiohttp/web_app.py:145: note:      Subclass:
aiohttp/web_app.py:145: note:          @overload
aiohttp/web_app.py:145: note:          def [_T] __getitem__(self, AppKey[_T]) -> _T
aiohttp/web_app.py:145: note:          @overload
aiohttp/web_app.py:145: note:          def __getitem__(self, str) -> Any

My assumption is that Any in the MutableMapping declaration means that it shouldn't care about the type in the subclass. But, also, _T is unbounded, so it accepts anything anyway.

Full code located at: https://github.com/aio-libs/aiohttp/pull/6498/files#diff-864083f9cc0dd7f38b50564bb430ddb33cf9123064b42b50decac1f9d7eca18c

@Dreamsorcerer
Copy link
Contributor Author

Not needed anymore, even if it is a bug.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug mypy got something wrong
Projects
None yet
Development

No branches or pull requests

1 participant