We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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
I am currently trying to apply type hints to a base class and its subclasses which override a classmethod:
from abc import ABCMeta, abstractmethod from typing import TypeVar, Type class MyBase(metaclass=ABCMeta): @classmethod @abstractmethod def foo(cls) -> MyBase: pass class MyChild(MyBase): @classmethod def foo(cls) -> MyChild: return MyChild() _MyT = TypeVar("_MyT", bound=MyBase) def bar(clazz: Type[_MyT]) -> _MyT: return clazz.foo()
Error:
example.py:19: error: Incompatible return value type (got "MyBase", expected "_MyT")
This seems to be incorrect, as returing MyBase is in bounds of _MyT.
MyBase
_MyT
I have found #2511 and its fix #7474 which should be merged in 0.761 but I still get this error.
0.761
Python: 3.8.1 MyPy: 0.761 (no custom flags)
The text was updated successfully, but these errors were encountered:
Using def foo(cls: Type[_MyT]) -> _MyT: solved this issue.
def foo(cls: Type[_MyT]) -> _MyT:
Sorry, something went wrong.
No branches or pull requests
I am currently trying to apply type hints to a base class and its subclasses which override a classmethod:
Error:
This seems to be incorrect, as returing
MyBase
is in bounds of_MyT
.I have found #2511 and its fix #7474 which should be merged in
0.761
but I still get this error.Python: 3.8.1
MyPy: 0.761 (no custom flags)
The text was updated successfully, but these errors were encountered: