python / python/mypy

New type analyzer: confusing error message for broken named tuple

Open
#6,956 0 comments 0 reactions 1 assignee View on GitHub

@JukkaL is already working on this.

Since Jun 12, 2019.

bug priority-1-normal semantic-analyzer topic-named-tuple
Dominant language
Python
Stars
20.6k
Forks
3.3k
PR merge metrics
PR metrics pending

Description

This test case fails:

[case testInvalidNamedTupleBaseClass]
from typing import NamedTuple

defer: Yes

class A(NamedTuple('N', [1])): pass # E: Tuple expected as NamedTuple() field

class Yes: ...

because there is a spurious additional error

main:5: error: Name 'namedtuple@5' already defined on line 5

See also #6422 that may be related (broken named tuples, and named tuples at function scope use similar logic).

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.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.