Closed
Description
This code typechecks cleanly:
from typing import List, NamedTuple
class Person(NamedTuple):
name: str
age: int
people: List[Person] = []
But add a self-referential attribute to the NamedTuple:
from typing import List, NamedTuple
class Person(NamedTuple):
name: str
age: int
kids: List['Person']
people: List[Person] = []
And now we get:
namedtuple.py:9: error: Incompatible types in assignment (expression has type List[<nothing>], variable has type List[Person])
If Person
is an ordinary class instead of a NamedTuple
, the error doesn't appear.