[New-bugs-announce] [issue44529] Using typing.Union in isinstance checks

Kaleb Barrett report at bugs.python.org
Mon Jun 28 14:15:36 EDT 2021


New submission from Kaleb Barrett <dev.ktbarrett at gmail.com>:

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: Subscripted generics cannot be used with class and instance checks

Seems like Unions could be used here interchangeably with tuples since they mean the same thing in this context. Of course this would only work if the element types are being capable of being used in isinstance checks.

----------
messages: 396658
nosy: ktbarrett
priority: normal
severity: normal
status: open
title: Using typing.Union in isinstance checks
type: enhancement

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue44529>
_______________________________________


More information about the New-bugs-announce mailing list