Closed mitar closed 6 years ago
Simply is_subtype(structural_type, Union[str, int, float, bool])
should do what you want if I understand your requirement correctly (otherwise, more context would be helpful).
Union[str, Union[int, bool]]
is equivalent to plain Union[str, int, bool]
(like Union[int]
is equivalent to plainint
) and I think pytypes handles this well (IIRC there are tests for it).
Oh, you are so right. Silly me. :-) Thanks!
In one part of my code, where I am deciding how to convert a value to JSON, I do:
What I realized is that I would be OK with all possible
Union
combinations of these as well. So ifstructural_type
isUnion[str, int]
that should also pass this check. Do you have a suggestion how to do so, or a helper function which would already do this? So I wonder about complicated case likeUnion[str, Union[int, bool]]
or something like that.