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
Here mypy, correctly, gives a type error, saying that, in class B, the first argument of f is incompatible with supertype A.
Now consider this class:
classC(A):
deff(self, x: X) ->None:
pass
mypy reports the same type error as for B. Is that correct? In a statically typed language, the definition of C should be okay. I'm still not completely familiar with gradual typing, so maybe I'm missing something again.
The text was updated successfully, but these errors were encountered:
Yeah, we could allow argument types to vary contravariantly, i.e. a subclass could override a method with more general argument types. This would actually be pretty useful, especially together with union types.
This is not supported currently due to this being potentially confusing when used with overloading. However, overloading is no longer needed that often, since union types are often a better alternative to overloading. Overloading with contravariance could still be supported as long the variants in an overload are not overlapping and they retain the order of the overridden definition.
Consider these classes:
Here mypy, correctly, gives a type error, saying that, in class
B
, the first argument off
is incompatible with supertypeA
.Now consider this class:
mypy reports the same type error as for
B
. Is that correct? In a statically typed language, the definition ofC
should be okay. I'm still not completely familiar with gradual typing, so maybe I'm missing something again.The text was updated successfully, but these errors were encountered: