We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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
Hello,
This is a question concerning NamedTuples. I'm using python 3.5.
Is there a way to create a namedtuple that relies on a typevar ?
I've tried this:
from typing import Optional, TypeVar, NamedTuple, Dict, Tuple, Generic MetaDataT = TypeVar("MetaDataT") def f(m: MetaDataT): State = NamedTuple("State", [("metadata", MetaDataT), ("new", bool), ("update", MetaDataT)])
But mypy complains by saying: error: 'MetaDataT' is a type variable and only valid in type context
error: 'MetaDataT' is a type variable and only valid in type context
So I tried to declare State outside of the function such as:
State
from typing import Optional, TypeVar, NamedTuple, Dict, Tuple, Generic MetaDataT = TypeVar("MetaDataT") State = NamedTuple("State", [("metadata", MetaDataT), ("new", bool), ("update", MetaDataT)])
But this time mypy complains by saying: error: Invalid type "debug.MetaDataT"
error: Invalid type "debug.MetaDataT"
I guess something like this coul work:
class S(NamedTuple, Generic[MetaDataT]): pass
But I'm using python 3.5 and this syntax is not supported.
The text was updated successfully, but these errors were encountered:
Mypy doesn't allow generic namedtuples; see python/mypy#685.
Sorry, something went wrong.
(This is a limitation in mypy though, not in the type system itself, so no need to keep this issue open.)
Yes, this is a duplicate of python/mypy#685.
No branches or pull requests
Hello,
This is a question concerning NamedTuples. I'm using python 3.5.
Is there a way to create a namedtuple that relies on a typevar ?
I've tried this:
But mypy complains by saying:
error: 'MetaDataT' is a type variable and only valid in type context
So I tried to declare
State
outside of the function such as:But this time mypy complains by saying:
error: Invalid type "debug.MetaDataT"
I guess something like this coul work:
But I'm using python 3.5 and this syntax is not supported.
The text was updated successfully, but these errors were encountered: