-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
New issue
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
Compatibility of method parameters of subclasses #424
Comments
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. For example, this should be fine:
|
Actually, after some contemplation I now feel that this should almost definitely be supported. |
Note that I haven't thought in much detail about how this works with multiple inheritance, but I don't see any problems. |
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: