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
In this issue, we shall discuss intersections with Callable. There is an unresolved issue with respect to Any & Callable, that stems from the following 2 axioms:
Intersections with Callable are resolved by intersecting with an equivalent Callback-Protocol (see current draft)
Both of these together can lead to infinite regress.
Therefore, we cannot use ① when intersecting function-types with function-types. One can distinguish 3 cases:
Intersections of function-types with non-function-types: then we can apply rule ①
Intersections of two function-types: regular subtyping and the more complicated function signature subtyping rules apply.
Intersections of function-types with Any
EDIT: The suggestions below are outdated. The intersection with Any is irreducible. What needs to be discussed is what happens when the type is attempted to be evaluated with arguments args.
As I see it, there are 2 options of how to resolve ③:
Ⓐ For a strict interpretation of Any as an unknown type, Any could feasibly be Callable[..., R], which is a "consistent" subtype of Callable[[T1, T2, ..., Tn], R]. It follows that:
Any & Callable[[T1, T2, ..., Tn], R] = Callable[..., R]
The consequence is that (Any & T).foo(*args, **kwargs), is valid for any method foo of T, which as expressed in the Any intersection thread causes some pains, as it makes Any & T behave very similar to Any itself (only attribute types and function return types are preserved)
Ⓑ An alternative approach would hinge on a slight re-interpretation of Any in the context of intersections. One could demand that Any shall be interpreted as a disjoint type from whatever it is intersected with (= maximum compatibility). That is, in Any & T, we interpret Any as an unknown type that presumably shares no overlapping methods with T. This leads to
I.e. we come back full circle to question if Any can be simplified away from intersections. Under this premise, we would have 3 simple rules, as I mentioned in #1 (comment)
Any & T is an irreducible form
(Any & T).foo ≅ T.foo if T implements foo
(Any & T).bar ≅ Any if T does not implement bar
So, does it make sense to have a general exemption to the rules #1 (comment) when intersecting Any with function-types?
In this issue, we shall discuss intersections with
Callable. There is an unresolved issue with respect toAny & Callable, that stems from the following 2 axioms:Callableare resolved by intersecting with an equivalent Callback-Protocol (see current draft)Anywithin an Intersection #1 (comment))Both of these together can lead to infinite regress.
Therefore, we cannot use ① when intersecting function-types with function-types. One can distinguish 3 cases:
AnyEDIT: The suggestions below are outdated. The intersection with
Anyis irreducible. What needs to be discussed is what happens when the type is attempted to be evaluated with argumentsargs.As I see it, there are 2 options of how to resolve ③:
Ⓐ For a strict interpretation of
Anyas an unknown type,Anycould feasibly beCallable[..., R], which is a "consistent" subtype ofCallable[[T1, T2, ..., Tn], R]. It follows that:The consequence is that
(Any & T).foo(*args, **kwargs), is valid for any methodfooofT, which as expressed in the Any intersection thread causes some pains, as it makesAny & Tbehave very similar toAnyitself (only attribute types and function return types are preserved)Ⓑ An alternative approach would hinge on a slight re-interpretation of
Anyin the context of intersections. One could demand thatAnyshall be interpreted as a disjoint type from whatever it is intersected with (= maximum compatibility). That is, inAny & T, we interpretAnyas an unknown type that presumably shares no overlapping methods withT. This leads toI.e. we come back full circle to question if
Anycan be simplified away from intersections. Under this premise, we would have 3 simple rules, as I mentioned in #1 (comment)Any & Tis an irreducible form(Any & T).foo≅T.fooifTimplementsfoo(Any & T).bar≅AnyifTdoes not implementbarSo, does it make sense to have a general exemption to the rules #1 (comment) when intersecting
Anywith function-types?