You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I don't know if this is my doing or a bug, but I encountered the error message in the title for my custom typing.py submodule:
from __future__ importannotationsfromtyping_extensionsimport*MediaType=Literal["v", "a", "s", "d", "t", "V"]
classStreamSpec_Options(TypedDict):
media_type: NotRequired[MediaType]
file_index: NotRequired[int]
program_id: NotRequired[int]
group_index: NotRequired[int]
group_id: NotRequired[int]
stream_id: NotRequired[int]
classStreamSpec_Index(StreamSpec_Options):
index: intclassStreamSpec_Tag(StreamSpec_Options):
tag: str|tuple[str, str]
classStreamSpec_Usable(StreamSpec_Options):
usable: boolStreamSpec=StreamSpec_Index|StreamSpec_Tag|StreamSpec_Usable# <<= error on this line
This works in py3.11. I initially only had __future__ import in place anticipating the compatibility issue for earlier Python versions. With NotRequired removed, it failed with plain typing.py with a different error message:
TypeError: unsupported operand type(s) for |: '_TypedDictMeta' and '_TypedDictMeta'
So, the difference in the error messages with/without typing_extensions makes me think that it's trying to support this annotation but something is off.
Is this a bug or am I doing something wrong? Thanks!
The text was updated successfully, but these errors were encountered:
You don't say what version of Python is giving you errors, but support for creating unions using | was added only in Python 3.10. typing_extensions does not attempt to support this feature on older versions, because it relies on a change in the core language (the addition of an __or__ method to builtins.type) that we cannot backport.
from __future__ import annotations does not matter for what you are doing because the place where you're seeing the error is not an annotation.
I don't know if this is my doing or a bug, but I encountered the error message in the title for my custom
typing.py
submodule:This works in py3.11. I initially only had
__future__
import in place anticipating the compatibility issue for earlier Python versions. WithNotRequired
removed, it failed with plaintyping.py
with a different error message:TypeError: unsupported operand type(s) for |: '_TypedDictMeta' and '_TypedDictMeta'
So, the difference in the error messages with/without
typing_extensions
makes me think that it's trying to support this annotation but something is off.Is this a bug or am I doing something wrong? Thanks!
The text was updated successfully, but these errors were encountered: