You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
It's happening! It's happening already and it's only Wednesday. Truly, your dire prophecy is unfolding as we type. 🙀
Would it be possible to use is_subhint like issubclass, with a tuple of types? For example:
Fascinating request. In theory, sure. In practice, is there much point? After all, @beartype already more-or-less supports this exact use case with:
Standard PEP 484- and 604-compliant unions: e.g.,
>>>frombeartype.doorimportis_subhint>>>is_subhint(str, int|str) # <-- PEP 604 union for the win, 'cause you just don't careTrue
A non-standard function that you yourself define that dynamically coerces tuples into PEP 484-compliant unions: e.g.,
>>>frombeartype.doorimportis_subhint>>>frombeartype.typingimportUnion# Function coercing tuples into unions. @beartype actually does this *A LOT* internally.# So, you just know that (A) it works and (B) it's questionable dark magic.>>>deftuple_to_union(hints: tuple) ->object:
returnUnion.__getitem__(hints)
>>>is_subhint(str, tuple_to_union((int, str))) # <-- tuple of types for the win, 'cause you do actually careTrue
Do either of those two examples support your use case? The second is really close to what you want. There's a tuple of types, which is good. There's also an intermediary conversion function, which is perhaps less good.
And now for the Ultimate Badness™. Since @beartype already more-or-less supports this, this is really low priority stuff for us... I've got five feature requests to feed this week. You wouldn't want to starve an orphan feature request, would you!?
leycec
changed the title
Use tuples as is_subhint superhints
[Feature Request] Generalize beartype.door.is_subhint() to accept type tuples... just 'cause
Apr 19, 2024
... Two more day 'til you get a deluge of replies!
Would it be possible to use
is_subhint
likeissubclass
, with a tuple of types? For example:Thank you kindly for the help!
The text was updated successfully, but these errors were encountered: