-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Should empty intersection be simplified? #20
Comments
Linking @kmillikin's prescient comment. |
Most people seemed to agree that if it should reduce then it should reduce to |
Yes, |
It's either This makes a difference, for instance in the from typing import TypeVarTuple, Intersection
protocols = TypeVarTuple("protocols")
# technically we want TypeVarTuple("protocols", bound=type[Protocol])
# but bounds are not supported yet for TypeVarTuple.
def merge_protocols(*protos: *protocols) -> Intersection[*Protocols]: ...
"""Creates the intersection of pairwise disjoint protocol classes."""
# if intersection is empty, returns a protocol that matches with any class.
# Note: https://peps.python.org/pep-0646/#args-as-a-type-variable-tuple Here, one would expect that this function can be chained with itself. But, for instance, consider what happens in the case of This shows that it makes a difference whether |
I would rather not treat empty intersections as object/any/typing.Top and just use the existing subtype rules "is it a subtype of all of these"? if it is empty, yes. The pragmatism of this is shown with TypeVarTuples. No special case or reduction needed here. I would not reduce to Any turning a static type into a gradual type, and if we go with object, protocols don't match (being equivalent or a subtype of) (but is that a bug?), so if we do reduce, I think the best option then is to have Intersection to an empty protocol, this relation with object does work. |
Just noticed an issue with this whole example, which is that currently PEP544 makes it impossible to type hint functions that return actual from typing import Protocol
def top() -> type[Protocol]: # error: Variable "typing.Protocol" is not valid as a type
class Top(Protocol):
pass
return Top |
Another reason to just leave empty intersection as empty intersection then |
@randolf-scholz Can we close this as not added to the specification? |
Sure. |
@randolf-scholz requests this here: #10 (comment)
If so, it should be added to the reductions.
The text was updated successfully, but these errors were encountered: