Open karamanolev opened 1 year ago
I think mypy's behavior here is correct (at least for the top code sample) because attr
will be treated as an instance method in the base class, but it's overridden as a static method in the child class. It's proper and useful for mypy to flag those as incompatible.
That doesn't explain why the error disappears in your second code sample. That looks like a bug (a false negative). Pyright flags both of these code samples as incompatible overrides.
Typing an attribute in a base class with
ClassVar[Optional[Callable]]
results in a type error even though the typing is seemingly sound.To Reproduce
Playground: https://mypy-play.net/?mypy=master&python=3.11&gist=4f52f561801eeb053b6d0a47c9afbc15
Expected Behavior
Mypy shouldn't return any errors.
Additionally, the same should happen when Callable is also typed itself, e.g. Callable[[str], None]. Right now both fail when they shouldn't.
Actual Behavior
Your Environment
mypy.ini
(and other config files): no relevant optionsAdditional information
Interestingly, if the callable doesn't have any arguments, mypy doesn't fail: