Message396671
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. |
|
Date |
User |
Action |
Args |
2021-06-28 23:30:14 | jack__d | set | recipients:
+ jack__d, ktbarrett |
2021-06-28 23:30:14 | jack__d | set | messageid: <1624923014.45.0.0827580043996.issue44529@roundup.psfhosted.org> |
2021-06-28 23:30:14 | jack__d | link | issue44529 messages |
2021-06-28 23:30:13 | jack__d | create | |
|