[issue44529] Using typing.Union in isinstance checks

2021-06-29 Thread Eric V. Smith
Change by Eric V. Smith : -- resolution: -> out of date stage: -> resolved status: open -> closed ___ Python tracker ___ ___

[issue44529] Using typing.Union in isinstance checks

2021-06-28 Thread Kaleb Barrett
Kaleb Barrett added the comment: Ah, this was implemented for 3.10 as a part of PEP 604. https://www.python.org/dev/peps/pep-0604/#isinstance-and-issubclass. Feel free to close. -- ___ Python tracker

[issue44529] Using typing.Union in isinstance checks

2021-06-28 Thread Jack DeVries
Jack DeVries added the comment: I think this already works unless you are using TypeVars:: t = Union[str, int] isinstance(1, t)# True isinstance('1', t) # True If you are using TypeVars, though, it cannot work: T = TypeVar('my_type') thing = Union[T, str]

[issue44529] Using typing.Union in isinstance checks

2021-06-28 Thread Kaleb Barrett
New submission from Kaleb Barrett : I have type aliases of Unions like so: Request = Union[WriteRequest, ReadRequest] I'd like to be able to use "Request" in an isinstance check rather than having to duplicate the information in a tuple to pass to the check. Currently I get: TypeError: