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
I just want to mention one more example here, which requires Union and Intersection, which is when the number of things intersected is variable. This can happen when TypeVarTuple are involved, and it kind of implies that a speccing of empty unions and empty intersections is necessary. (See python/typing#1362)
fromtypingimportTypeVarTuple, Unionitems=TypeVarTuple("items")
protocols=TypeVarTuple("protocols") # something like tuple[type[Protocol], ...]defpick_random_element(tup: tuple[*items]) ->Union[*items]: ...
"""Return random element form a tuple."""# if tuple is empty, raises an exception ⟺ return `Never`.defcreate_intersection_protocol(tuple: tuple[*protocols]) ->type[Intersection[*Protocols]]: ...
"""Creates the intersection of pairwise disjoint protocol classes."""# if intersection is empty, returns a protocol that matches with any class.EMPTY_TUPLE= ()
pick_random_element(EMPTY_TUPLE) # should reveal as `Never`.create_intersection_protocol(EMPTY_TUPLE) # should reveal as `object`!?
Note that bounds are (not yet) supperted by TypeVarTuple, so the latter cannot be hinted properly right now.
The text was updated successfully, but these errors were encountered:
NeilGirdhar
changed the title
I just want to mention one more example here, which requires Union and Intersection, which is when the number of things intersected is variable. This can happen when TypeVarTuple are involved, and it kind of implies that a speccing of empty unions and empty intersections is necessary. (See https://github.com/python/typing/issues/1362)
Support variable intersections
Aug 4, 2023
I just want to mention one more example here, which requires
Union
andIntersection
, which is when the number of things intersected is variable. This can happen whenTypeVarTuple
are involved, and it kind of implies that a speccing of empty unions and empty intersections is necessary. (See python/typing#1362)Note that bounds are (not yet) supperted by
TypeVarTuple
, so the latter cannot be hinted properly right now.Originally posted by @randolf-scholz in #12 (comment)
The text was updated successfully, but these errors were encountered: