Generic NamedTuples and overloads
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 20.6k
- Forks
- 3.3k
- PR merge metrics
- PR metrics pending
Description
mypy doesn't infer the right type, when using a generic namedtuple and overloads.
To Reproduce
https://gist.github.com/mypy-play/60399580f537f8a7c80bb18266ab357f
Expected Behavior
Revealed type is int (pyright infers the right type).
Actual Behavior
Mypy infers type "< nothing >". Removing "NamedTuple" as a base class fixes the problem. So this seems to be related to the way mypy handles generic namedtuples.
Your Environment
- Mypy version used: 0.981
- Python version used: 3.10.7
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 linked gist reproduction and run it against mypy 0.981 with Python 3.10.7, then compare the inferred type with the expected int result. Investigate the generic NamedTuple and overload behavior shown there; done means mypy infers int rather than without removing NamedTuple.
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
- Mostly clear
- Newbie friendliness
- 38/100