From 13791bb5114d499ffa314ea69d56a53a9afa6160 Mon Sep 17 00:00:00 2001 From: hauntsaninja Date: Tue, 31 Dec 2024 16:36:54 -0800 Subject: [PATCH] Add regression test for NamedTuple with recursive bound See https://github.com/python/mypy/pull/18351#pullrequestreview-2525435197 --- test-data/unit/check-namedtuple.test | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/test-data/unit/check-namedtuple.test b/test-data/unit/check-namedtuple.test index 566b5ef57350..172228820add 100644 --- a/test-data/unit/check-namedtuple.test +++ b/test-data/unit/check-namedtuple.test @@ -1460,3 +1460,17 @@ Func = NamedTuple('Func', [ ]) [builtins fixtures/tuple.pyi] [typing fixtures/typing-namedtuple.pyi] + +[case testGenericNamedTupleRecursiveBound] +from typing import Generic, NamedTuple, TypeVar +T = TypeVar("T", bound="NT") +class NT(NamedTuple, Generic[T]): + parent: T + item: int + +def main(n: NT[T]) -> None: + reveal_type(n.parent) # N: Revealed type is "T`-1" + reveal_type(n.item) # N: Revealed type is "builtins.int" + +[builtins fixtures/tuple.pyi] +[typing fixtures/typing-namedtuple.pyi]