You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
It looks like mypy already prohibits covariant overriding of mutable attributes if one of them is a method, unlike for variables (see #3208), which is quite funny.
Note however, this is not a bug, this is actually unsafe code:
y=Sub()
x: Base=yx.formatter2=Noney.formatter2(42) # Oops, TypeError: NoneType not callable.
Actually, on the second thought I think we should keep this open for cryptic error message. It should explain that the problem here is mutability in superclass.
ilevkivskyi
changed the title
False positive with staticmethod and Optional Callable
Bad error message for covariant overriding of a mutable attribute
Aug 12, 2019
Hmm, indeed this is unsafe in general. The way I use this pattern is to define optional operations, so these fields will never be modified at runtime, but there is no way for mypy to know that.
When I check this with mypy 0.711:
It reports:
I would expect all four formatters to be accepted, but for some reason
formatter2
is not.It doesn't make a difference whether I use the old or new semantic analyzer.
The text was updated successfully, but these errors were encountered: