Better error message for incompatible assignment to method
Nobody has claimed this yet.
Assessment
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Newbie friendliness
- 25/100
Research direction
Reproduce the reported NamedTuple example with mypy and inspect how the index field is checked against tuple's inherited index method. Determine whether the fix belongs in mypy or typeshed; done means the sample type-checks without errors and the regression is covered by an appropriate test.
Written by the indexing model from the issue text.
Description
Note
I am not sure whether it should be reported here or to the typeshed repo. Reporting here for now. If this is a typeshed issue, I'll gladly open issue there and close this one.
If there is something special in index field in NamedTuple, please point out to the corresponding documentation as I failed to find anything on topic.
Description
Type
bug
Code to check
from typing import NamedTuple
class Foo(NamedTuple):
index: str
Actual behavior
test.py:5: error: Incompatible types in assignment (expression has type "str", base class "tuple" defined the type as "Callable[[Tuple[str, ...], Any, int, int], int]")
Expected behavior
No errors while typechecking
Environment
$ mypy -V
mypy 0.560
$ python -V
Python 3.6.4
Behavior is still the same when using mypy from master:
$ mypy -V
mypy 0.570-dev-7192a7578fc47530bbb5382984d289bffa72b30b
$ mypy test.py
test.py:5: error: Incompatible types in assignment (expression has type "str", base class "tuple" defined the type as "Callable[[Tuple[str, ...], Any, int, int], int]")
- 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
-
fix: inaccuracy ⚠️
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
uabrc/uabrc.github.io#1255 · 1 comment ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 84/100
ethereum-optimism/factory#64 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 90/100
duckdb/duckdb-python#627 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
-
documentation
Difficulty 1/5 Under an hour Newbie friendliness 78/100
Qiskit/qiskit-addon-sqd#376 ·