Message285410
typing.Union prevents the use of `isinstance` and `issubclass` via a hook.
This is presumably to prevent errors that would arise if someone tried to do issubclass(A, Union[A, B]) or isinstance(A(), Union[A, B]), because Union isn’t specified in the PEP to allow a check like this, and doesn’t implement it. (Instead it throws said error)
However, as far as I can see there is no blessed way to check if an object was returned by Union.__getitem__(). A simple way that works is:
sig = inspect.signature(f)
ann = sig.parameters['arg1'].annotation
is_an_union = isinstance(ann, typing._Union)
but _Union is a private class, and an implementation detail.
is there a blessed way to do this? If not, one should be added. |
|
Date |
User |
Action |
Args |
2017-01-13 15:45:47 | flying sheep | set | recipients:
+ flying sheep |
2017-01-13 15:45:47 | flying sheep | set | messageid: <1484322347.31.0.5780880295.issue29262@psf.upfronthosting.co.za> |
2017-01-13 15:45:47 | flying sheep | link | issue29262 messages |
2017-01-13 15:45:46 | flying sheep | create | |
|