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
mypy version 0.942
0.942
With test.py like this:
test.py
from abc import ABC, abstractmethod class AbstractClass(ABC): @abstractmethod def method(self): pass class ConcreteClass1(AbstractClass): def method(self): print("hello") class ConcreteClass2(AbstractClass): def method(self): print("hello") class ConcreteClass3(AbstractClass): def method(self): print("hello") classes = [ ConcreteClass1, ConcreteClass2, ConcreteClass3, ] for c in classes: c().method()
Mypy shows:
test.py:27: error: Cannot instantiate abstract class "AbstractClass" with abstract attribute "method"
Some weird behavior I've noticed:
If, instead of a loop, I do this:
... ConcreteClass1().method() ConcreteClass2().method() ConcreteClass3().method()
mypy is happy.
Also, if, instead of 3 classes in the loop, I do 2:
classes = [ ConcreteClass1, ConcreteClass2, #ConcreteClass3, ] for c in classes: c().method()
mypy is happy with that as well. I posted this on stackoverflow, and this seems to be a bug.
This can be worked around by explicitly defining the type of list:
classes: List[Type[AbstractClass]] = [ ConcreteClass1, ConcreteClass2, ConcreteClass3, ]
The text was updated successfully, but these errors were encountered:
Duplicate of #3115
Sorry, something went wrong.
No branches or pull requests
mypy version
0.942
With
test.py
like this:Mypy shows:
test.py:27: error: Cannot instantiate abstract class "AbstractClass" with abstract attribute "method"
Some weird behavior I've noticed:
If, instead of a loop, I do this:
mypy is happy.
Also, if, instead of 3 classes in the loop, I do 2:
mypy is happy with that as well.
I posted this on stackoverflow, and this seems to be a bug.
This can be worked around by explicitly defining the type of list:
The text was updated successfully, but these errors were encountered: