-
Notifications
You must be signed in to change notification settings - Fork 263
Closed
Labels
topic: featureDiscussions about new features for Python's type annotationsDiscussions about new features for Python's type annotations
Description
Currently, in python 3.7, it seems impossible to properly compose typing.NamedTuple
and typing.Generic
. That is, I want to do this:
import typing
T = typing.TypeVar("T")
class Test(typing.NamedTuple, typing.Generic[T]):
a: T
So this works, the class can be used as a NamedTuple
.
However:
x: Test[int] = Test(a=1) # TypeError: 'type' object is not subscriptable
Right, subclassing NamedTuple
generates a class that inherits only from tuple
.
Maybe this was discussed before, I've looked a bit in this repo and haven't found much, except #588, which doesn't really address this.
Is there any plan or possibility for this to be resolved? Maybe more generally, allowing NamedTuple
to be composable with other types(I know this might be difficult because of metaclass conflicts).
Thanks!
benoit-dubreuil
Metadata
Metadata
Assignees
Labels
topic: featureDiscussions about new features for Python's type annotationsDiscussions about new features for Python's type annotations