Skip to content
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

False negative: override signature check allows mismatched param names? #14639

Closed
a-reich opened this issue Feb 7, 2023 · 1 comment
Closed
Labels
bug mypy got something wrong

Comments

@a-reich
Copy link

a-reich commented Feb 7, 2023

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 version used: 1.0.0
  • Mypy command-line flags: --strict
  • Mypy configuration options from mypy.ini (and other config files):
  • Python version used: 3.11

Thanks, mypy folks, for all your work on this awesome tool!

@a-reich a-reich added the bug mypy got something wrong label Feb 7, 2023
@hauntsaninja
Copy link
Collaborator

Thanks, this is a duplicate of #1013

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.

@hauntsaninja hauntsaninja closed this as not planned Won't fix, can't repro, duplicate, stale Feb 7, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug mypy got something wrong
Projects
None yet
Development

No branches or pull requests

2 participants