-
Notifications
You must be signed in to change notification settings - Fork 258
Combining Generic and NamedTuple #653
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
Comments
Something of a workaround:
But unsurprisingly mypy won't accept this:
|
It seems this is being worked on in python/mypy#685. |
It's also impossible to do from typing import TypedDict, TypeVar, Generic
T = TypeVar('T')
class Test(TypedDict, Generic[T]):
a: T with error |
If a type checker doesn't support this, this seems to be more of a type checker issue than a general typing issue, so I'm closing this here. |
Typing currently bans this in mro entries |
This is now:
So I think this feature request can be closed as "accepted"! |
Currently, in python 3.7, it seems impossible to properly compose
typing.NamedTuple
andtyping.Generic
. That is, I want to do this:So this works, the class can be used as a
NamedTuple
.However:
Right, subclassing
NamedTuple
generates a class that inherits only fromtuple
.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!
The text was updated successfully, but these errors were encountered: