python / python/mypy

Unexpected arguments type error

Open
#8,651 4 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

false-positive feature priority-2-low
Dominant language
Python
Stars
20.6k
Forks
3.3k
PR merge metrics
PR metrics pending

Description

Below code provides example:

MergeStrategy = NamedTuple(
typename="MergeStrategy",
fields=[("left", str), ("right", str), ("how", str), ("on", List[str])],
)
Generates error
{
"resource": <>,
"owner": "python",
"code": "error",
"severity": 8,
"message": "Unexpected arguments to namedtuple()",
"source": "mypy",
"startLineNumber": 53,
"startColumn": 18,
"endLineNumber": 53,
"endColumn": 18
}

whereas this does not:
MergeStrategy = NamedTuple(
"MergeStrategy", [("left", str), ("right", str), ("how", str), ("on", List[str])],
)

Same thing for regular namedtuple.

get same error with this:
MergeStrategy = namedtuple(typename="MergeStrategy", field_names=["left", "right", "how", "on"])

but this is fine:
MergeStrategy = namedtuple("MergeStrategy", ["left", "right", "how", "on"])

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

No file or test is named. Start by reproducing the reported mypy errors for NamedTuple and namedtuple calls with keyword arguments, then trace the argument handling for these constructors. Done means the keyword and positional forms are checked consistently, with regression coverage for the examples.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.