Skip to content

Commit 191a5d7

Browse files
committed
some support for generic namedtuple
1 parent 7a40ac4 commit 191a5d7

2 files changed

Lines changed: 13 additions & 3 deletions

File tree

‎mypy/typeanal.py‎

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -226,9 +226,6 @@ def visit_unbound_type(self, t: UnboundType) -> Type:
226226
if tup is not None:
227227
# The class has a Tuple[...] base class so it will be
228228
# represented as a tuple type.
229-
if t.args:
230-
self.fail('Generic tuple types not supported', t)
231-
return AnyType()
232229
return tup.copy_modified(items=self.anal_array(tup.items),
233230
fallback=instance)
234231
td = info.typeddict_type

‎test-data/unit/check-class-namedtuple.test‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -480,3 +480,16 @@ Y(y=1, x='1').method()
480480
class CallsBaseInit(X):
481481
def __init__(self, x: str) -> None:
482482
super().__init__(x)
483+
484+
[case testNewNamedTupleGeneric]
485+
# flags: --python-version 3.6
486+
from typing import NamedTuple, Generic, TypeVar
487+
T = TypeVar('T')
488+
class A(NamedTuple, Generic[T]):
489+
x: T
490+
y: str
491+
492+
a : A[int]
493+
reveal_type(a.x) # E: Revealed type is 'builtins.int*'
494+
b : A[str]
495+
reveal_type(b.x) # E: Revealed type is 'builtins.str*'

0 commit comments

Comments
 (0)