Skip to content

NamedTuple single line declaration gives error "Too many arguments for NamedTuple() [misc] #11047

Open
@yesthesoup

Description

@yesthesoup

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions