Skip to content

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

Closed as not planned
@a-reich

Description

@a-reich

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!

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugmypy got something wrong

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions