Confusing error when assigning to method defined in base class
Nobody has claimed this yet.
Assessment
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Newbie friendliness
- 35/100
Research direction
Start by reproducing both examples and tracing the assignment check for a method inherited from a base class. Compare it with normal override checking, then verify that compatible assignments pass and that any remaining argument-name diagnostic includes Arg('name', ...).
Written by the indexing model from the issue text.
Description
The error on the last line of this program doesn't make sense, since the types seems compatible:
class C:
def f(self, x: int) -> None: pass
class D(C):
def g(self, y: object) -> None: pass
f = g # Incompatible types in assignment (expression has type Callable[[object], None],
# base class "C" defined the type as Callable[[int], None])
There are actually two issues going on. If we update the code a little, the error message looks more reasonable:
class C:
def f(self, x: int) -> None: pass
class D(C):
def g(self, y: int) -> None: pass
f = g # Incompatible types in assignment (expression has type Callable[[Arg('y', int)], None],
# base class "C" defined the type as Callable[[Arg('x', int)], None])
Here's my analysis:
- Both the examples should probably be okay. We shouldn't do strict callable argument name checking here, for consistency with normal override checks. If we'd use a normal override (
def f(...)), there would be no error. - The error message in the first example is not good. We should include
Arg('name', ...)in the message if the error is due to an argument name mismatch.
- Dominant language
- Python
- Stars
- 20.6k
- Forks
- 3.3k
- Avg merge
- 1d 18h
- Merged PRs (30d)
- 54
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.
More from python/mypy
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
-
documentation
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
-
bug topic-configuration topic-error-reporting
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
Similar issues
-
🐛 Bug 🔔 Pending processing
Difficulty 2/5 1-3 hours Newbie friendliness 84/100
jumpserver/jumpserver#17584 ·
-
link-check link-check:sphinx-theme
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 65/100
qgis/QGIS-Documentation#11275 ·
-
bug priority:normal ready-for-dev
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
OpenHands/extensions#626 · 1 comment ·
-
Difficulty 1/5 Under an hour Newbie friendliness 90/100
CSCfi/sd-search-api#39 ·