Reassigned method raises "signature incompatible with supertype"
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 20.6k
- Forks
- 3.3k
- PR merge metrics
- PR metrics pending
Description
Bug Report
A rather simple class with an aliased method raises "signature incompatible with supertype" - which seems to happen due to the method name (i can't really find something else that's wrong).
To Reproduce
class A:
def hello(self, a: str, b: str):
pass
world = hello
class B(A):
# Also tried without ":A" on the self argument
def world(self: A, a: str, b: str):
# Do something slightly different when child-class is the instance
pass
Expected Behavior
Mypy should pass - as the function signature is correct except for the method name.
It should obviously flag if an argument is missing (or named wrongly).
The only workaround to the above error is to actually implement world in the parent class - which is obviously what i'd like to avoid as that'll be unnecessary code, and one unnecessary additional function call and nesting level.
# type: ignore[override] on the "world" method does not circumvent this problem
Actual Behavior
mypy_decoroator.py:12: error: Signature of "world" incompatible with supertype "A"
mypy_decoroator.py:12: note: Superclass:
mypy_decoroator.py:12: note: def hello(self: A, a: str, b: str) -> Any
mypy_decoroator.py:12: note: Subclass:
mypy_decoroator.py:12: note: def world(self, a: str, b: str) -> Any
(Write what happened.)
Your Environment
- Mypy version used:0.942
- Mypy command-line flags: N/A
- Mypy configuration options from
mypy.ini(and other config files): n/A - Python version used: 3.9.7
- Operating system and version: linux
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the minimal class A/B reproducer in the issue and run mypy against it to confirm the reported diagnostic. Trace how the aliased method is compared with the superclass method; done when the compatible alias is accepted while missing or incorrectly named arguments still produce an override error.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- devtools
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 38/100