-
-
Notifications
You must be signed in to change notification settings - Fork 33.2k
Closed as not planned
Closed as not planned
Copy link
Labels
Description
Bug report
Bug description:
When creating a type alias
, it seems like forward referencing does not work as expected when using union type operator
.
This works fine
from typing import Union
ABC = dict[str, Union[list[str], "ABC"]]
But this does not
ABC = dict[str, list[str] | "ABC"]
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: unsupported operand type(s) for |: 'types.GenericAlias' and 'str'
On python:3.14
, I also tried to use the new PEP 649:
ABC = dict[str, list[str] | ABC]
Traceback (most recent call last):
File "<python-input-1>", line 1, in <module>
ABC = dict[str, list[str] | ABC]
^^^
NameError: name 'ABC' is not defined
This is the same when using Union
from typing import Union
ABC = dict[str, Union[list[str], ABC]]
NameError: name 'ABC' is not defined
CPython versions tested on:
3.11, 3.12, 3.13, 3.14
Operating systems tested on:
macOS