From 02c07c893c47200e7da52a29e6ed7f05e2d63f52 Mon Sep 17 00:00:00 2001 From: Shantanu <12621235+hauntsaninja@users.noreply.github.com> Date: Mon, 6 Jan 2025 12:21:25 -0800 Subject: [PATCH] Add regression test for NamedTuple with recursive bound (#18399) See https://github.com/python/mypy/pull/18351#pullrequestreview-2525435197 Co-authored-by: ilevkivskyi --- 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]