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
Bug Report
When a subclass overrides a method, mypy says that it checks for compatibility of the signature, using the principle "The signature of a method in a subclass should accept all valid calls to the base class method". However, it seems to allow omitting an ordinary named parameter as long as some param with different name in the same position exists.
This works OK in some sense as long as callers use the parent param positionally (although could result in wrong semantics if the child class interprets the param as a completely different thing), but valid calls using a keyword will fail. IMO, I would have expected this to be considered unsafe.
Note that if either method makes the param keyword-only is in fact considered incompatible.
Also, I would point out that this is different than how mypy checks callable protocols, which enforces names to match as expected (also shown in example).
The reasoning here predates the introduction of positional-only parameters in Python 3.8 (and as you noticed, we were able to strictify things with Protocols, since that was not constrained by having to describe existing code). Now that Python 3.7 is soon to be end-of-life, it might be worth picking this up.
Bug Report
When a subclass overrides a method, mypy says that it checks for compatibility of the signature, using the principle "The signature of a method in a subclass should accept all valid calls to the base class method". However, it seems to allow omitting an ordinary named parameter as long as some param with different name in the same position exists.
This works OK in some sense as long as callers use the parent param positionally (although could result in wrong semantics if the child class interprets the param as a completely different thing), but valid calls using a keyword will fail. IMO, I would have expected this to be considered unsafe.
Note that if either method makes the param keyword-only is in fact considered incompatible.
Also, I would point out that this is different than how mypy checks callable protocols, which enforces names to match as expected (also shown in example).
To Reproduce
https://gist.github.com/mypy-play/17eeaa37eef6fdc56aab8870581678ba
Expected Behavior
definition of
load
in Child should get flagged as incompatible override.Actual Behavior
no mypy error for the method def.
Your Environment
mypy.ini
(and other config files):Thanks, mypy folks, for all your work on this awesome tool!
The text was updated successfully, but these errors were encountered: