Open euresti opened 8 years ago
Right, __call__
(and any other dunder methods) must be defined on the class. This is tricky to fix until we refactor some things in mypy to teach it about the relationship between class and instance variables and how they differ.
Can we close this or is there an action item for mypy?
Well how do we feel about code that typechecks but fails when used as expected? It's basically a false positive.
I think that's called a false negative :-) but you're right that that's an
issue. It's more general though -- mypy just doesn't distinguish between
class and instance attributes very well. (The rules for dunder methods are
also super special, it's not just __call__
.) I'll go look for an existing
issue about that; if I can't find one I'll rename this one.
The bug is really that mypy doesn't understand the difference between classes and instances enough, and that dunder methods must be defined on the class in order to apply to the instance.
I thought I had a found a great workaround for a problem I'm having. I'll define
__call__
in the__init__
Mypy has no issues with this code at all. However python2 disagrees:
Looks like
__call__
has to be defined on the class not the instance.