Skip to content

cannot use | union syntax in recursive types #100325

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

Closed
ShayHill opened this issue Dec 17, 2022 · 1 comment
Closed

cannot use | union syntax in recursive types #100325

ShayHill opened this issue Dec 17, 2022 · 1 comment
Labels
topic-typing type-bug An unexpected behavior, bug, or error

Comments

@ShayHill
Copy link

Bug report

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

@ShayHill ShayHill added the type-bug An unexpected behavior, bug, or error label Dec 17, 2022
@AlexWaygood
Copy link
Member

Duplicate of #90015

@AlexWaygood AlexWaygood marked this as a duplicate of #90015 Dec 17, 2022
@AlexWaygood AlexWaygood closed this as not planned Won't fix, can't repro, duplicate, stale Dec 17, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
topic-typing type-bug An unexpected behavior, bug, or error
Projects
None yet
Development

No branches or pull requests

2 participants