inner class of NamedTuple triggers "Invalid statement"
Open
Nobody has claimed this yet.
bug
topic-named-tuple
- Dominant language
- Python
- Stars
- 20.6k
- Forks
- 3.3k
- PR merge metrics
- PR metrics pending
Description
This will show an error.
from typing import NamedTuple
class Name(NamedTuple):
name: str = ""
class Inner:
pass
>>> error: Invalid statement in NamedTuple definition; expected "field_name: field_type [= default]"
However, this works fine:
class Name:
name: str = ""
class Inner:
pass
mypy 0.761
Python 3.8.5 (default, Jan 27 2021, 15:41:15)
[GCC 9.3.0] on linux
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
Reproduce the reported case using the NamedTuple definition with a nested Inner class, then trace the NamedTuple definition handling that emits the "Invalid statement" diagnostic. Compare it with the ordinary class example; done means the nested class is accepted without that diagnostic while existing field validation remains intact.
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
- 45/100