Author flying sheep
Recipients flying sheep
Date 2017-01-13.15:45:46
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1484322347.31.0.5780880295.issue29262@psf.upfronthosting.co.za>
In-reply-to
Content
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.
History
Date User Action Args
2017-01-13 15:45:47flying sheepsetrecipients: + flying sheep
2017-01-13 15:45:47flying sheepsetmessageid: <1484322347.31.0.5780880295.issue29262@psf.upfronthosting.co.za>
2017-01-13 15:45:47flying sheeplinkissue29262 messages
2017-01-13 15:45:46flying sheepcreate