NamedTuple single line declaration gives error "Too many arguments for NamedTuple() [misc]
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 20.6k
- Forks
- 3.3k
- PR merge metrics
- PR metrics pending
Description
Bug Report
typing.NamedTuple one line declaration gives incorrect error
To Reproduce
# test.py
from typing import NamedTuple
ExampleClass = NamedTuple('ExampleClass', test_id=str, timestamp=str)
mypy --show-error-codes test.py
test.py:[line-no]: error: Too many arguments for NamedTuple() [misc]
Expected Behavior
mypy doesn't give this error
given the above syntax is valid python and works fine, I would expect it to not throw an error, like the following old structure declaration does not, which is labeled as "back-ward compatible usage" in the official doc
ExampleClass = NamedTuple('ExampleClass', [(test_id, str), (timestamp, str)])
Actual Behavior
error: Too many arguments for NamedTuple() [misc]
Your Environment
mypy --version
mypy 0.910
python --version
3.8.10
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 by running the reported test.py example with mypy --show-error-codes and inspect the NamedTuple call handling. Done means the keyword-based one-line declaration no longer produces the erroneous "Too many arguments for NamedTuple()" error, while the existing list-based declaration remains accepted; add a regression test if the repository's test location is identified.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- devtools
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 45/100