Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Generic NamedTuple not working #5112

Closed
phdowling opened this issue May 25, 2018 · 1 comment
Closed

Generic NamedTuple not working #5112

phdowling opened this issue May 25, 2018 · 1 comment

Comments

@phdowling
Copy link

First of all, I hope this is the right place for this, if not, just let me know.

I'm trying to create a generic version of a NamedTuple, as follows:

T1 = TypeVar("T1")
T2 = TypeVar("T2")

class Group(NamedTuple, Generic[T1, T2]):
    key: T1
    group: List[T2]

g = Group(1, [""])  # expecting type to be G[int, str]

However, I get the following error:
TypeError: metaclass conflict: the metaclass of a derived class must be a (non-strict) subclass of the metaclasses of all its bases

I'm not sure how else to achieve what I'm trying to do here, or if this might be a bug in the typing mechanism on some level.

Any help?

@ilevkivskyi
Copy link
Member

ilevkivskyi commented May 25, 2018

Generic tuple types are not supported in mypy, see #685

In Python 3.7 this should work at runtime, but mypy will still not be able to type check this. Closing as a duplicate of #685

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants