Jack DeVries <jdevries3...@gmail.com> 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]

    isinstance('hi', thing)  # Exception

This makes sense, because ``T`` is just a name, not related to an actual object.

Sorry if I'm missing something, because I did try the non-working example and 
my exception actually says, "issubclass() arg 2 must be a class, a tuple of 
classes, or a union." The exception makes sense, but its difference from yours 
might mean I'm doing something differently.

----------
nosy: +jack__d

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

Reply via email to