Allow keyword arguments when creating namedtuple
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 20.6k
- Forks
- 3.3k
- PR merge metrics
- PR metrics pending
Description
Bug Report
The program:
from collections import namedtuple
Point = namedtuple(typename='Point', field_names=['x', 'y'])
p_1 = Point(2, 7)
The first line is marked by mypy:
Unexpected arguments to "namedtuple()" [misc]
I think it should be allowed to use argument names in the call.
The second line is marked so:
Too many arguments for "Point" [call-arg]
I think this is definitely a false positive.
(A clear and concise description of what the bug is.)
To Reproduce
# Ideally, a small sample program that demonstrates the problem.
# Or even better, a reproducible playground link https://mypy-play.net/ (use the "Gist" button)
Expected Behavior
Actual Behavior
Your Environment
- Mypy version used: 1.7.1
- Mypy command-line flags: None
- Mypy configuration options from
mypy.ini(and other config files): None - Python version used: 3.11.4
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 collections.namedtuple reproducer and run mypy on it to confirm both diagnostics. Trace how namedtuple calls and the generated Point constructor are analyzed; done means keyword arguments are accepted and the false-positive error on Point(2, 7) is gone.
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
- Mostly clear
- Newbie friendliness
- 43/100