Ken Jin <kenjin4...@gmail.com> added the comment:

@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]

----------

_______________________________________
Python tracker <rep...@bugs.python.org>
<https://bugs.python.org/issue45418>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to