This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author kj
Recipients gvanrossum, joperez, kj, serhiy.storchaka
Date 2021-10-10.15:38:27
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1633880307.4.0.863094968996.issue45418@roundup.psfhosted.org>
In-reply-to
Content
@Guido,

I hope I didn't misunderstand you, but to clarify, what OP is asking is an alternative way to construct types.UnionType objects and write:

types.UnionType[int, str]

like how we used to write before 3.10:

typing.Union[int, str]

I don't know why we need this. We can write `int | str`. The reason for PEP 604 in the first place was to avoid the subscript syntax and use `|` since it's cleaner. OP's use case is for reconstructing types.UnionType objects easily, but `functools.reduce(operator.or_, args)` works.

Re: TypeVar subscription; PEP 604 syntax already supports that. We used to implement that in C. After Serhiy's Great Cleanup, a bitwise OR with a TypeVar automatically converts types.UnionType to typing.Union. So all the TypeVar support is now done in Python.

>>> type(int | str)
<class 'types.UnionType'>

>>> (int | str | T)[dict]
typing.Union[int, str, dict]
History
Date User Action Args
2021-10-10 15:38:27kjsetrecipients: + kj, gvanrossum, serhiy.storchaka, joperez
2021-10-10 15:38:27kjsetmessageid: <1633880307.4.0.863094968996.issue45418@roundup.psfhosted.org>
2021-10-10 15:38:27kjlinkissue45418 messages
2021-10-10 15:38:27kjcreate