Python 11.1 accepts recurring type definition with the Union[] syntax
>>> from typing import Union
>>> NestedList = list[Union[str, "NestedList"]]
>>> NestedList
list[typing.Union[str, ForwardRef('NestedList')]]
However, the more recent | union syntax fails
>>> NestedList = list[str | "NestedList"]
TypeError: unsupported operand type(s) for |: 'type' and 'str'
Your environment
CPython versions tested on:
Python 3.10.8 (tags/v3.10.8:aaaf517, Oct 11 2022, 16:37:59) [MSC v.1933 32 bit (Intel)] on win32
Python 3.11.0 (main, Oct 24 2022, 18:13:38) [MSC v.1933 32 bit (Intel)] on win32
Python 3.11.1 (tags/v3.11.1:a7a450f, Dec 6 2022, 19:58:39) [MSC v.1934 64 bit (AMD64)] on win3
Operating system and architecture:
Intel(R) Core(TM) i7-10610U CPU @ 1.80GHz 2.30 GHz
The text was updated successfully, but these errors were encountered:
ShayHill commentedDec 17, 2022
Bug report
Python 11.1 accepts recurring type definition with the
Union[]
syntaxHowever, the more recent
|
union syntax failsYour environment
CPython versions tested on:
Python 3.10.8 (tags/v3.10.8:aaaf517, Oct 11 2022, 16:37:59) [MSC v.1933 32 bit (Intel)] on win32
Python 3.11.0 (main, Oct 24 2022, 18:13:38) [MSC v.1933 32 bit (Intel)] on win32
Python 3.11.1 (tags/v3.11.1:a7a450f, Dec 6 2022, 19:58:39) [MSC v.1934 64 bit (AMD64)] on win3
Operating system and architecture:
Intel(R) Core(TM) i7-10610U CPU @ 1.80GHz 2.30 GHz
The text was updated successfully, but these errors were encountered: