-
Notifications
You must be signed in to change notification settings - Fork 237
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
An Intersection type? #18
Comments
(In README.text, Łukasz suggested to use Any[] instead of Union[] so that All[] can be used as Intersection[]. Feels a bit cute to me.) |
Having intersections is important since we don't have structural sub-classing and protocols will likely not be composable with ABCs. Any/All is not only cute, it's also shorter to type and more obvious to the reader :) |
Łukasz, can you show a few examples of how Any/All would be used? Your README note was rather cryptic. I agree Intersection is verbose, but it sounds like a minor use case, and I don't want to lose unparameterized Any as the top (or is that bottom? :-) of the type tree/graph. |
I think this would be occasionally useful, but clearly this would be a minor feature. I vote for leaving this out for now and waiting until we have seen some real-world use cases that would benefit from intersection types. |
Agreed. Let's skip it for now then. |
What I proposed is alternative names: Union becomes Any, Intersection becomes All. typevar(values=) could become OneOf, with the bracket syntax, which would be more consistent. Examples:
Note that
Of course, we could provide more sensible ABCs for "file-like" objects, etc. I deal with cache invalidation for a living, naming things and off-by-one errors are just a hobby. |
Sorry, I don't like any of that. Can we just drop it?
|
OK, that covers it. No Intersection for now, names stay as they were. |
Its been a number of years since this thread was first opened, so I wanted to bump on it. From my perspective, the lack of an intersection type is one of the key flaws of the python type system at current, and its introduction would be majorly beneficial. |
There is an open issue about this, #213. |
+1 comments are better done via emoji than by tagging people. In any case, #213 is the issue tracking this feature. |
Sometimes you want to say that an argument must follow two or more different protocols. For example, you might want to state that an argument must be an Iterable and a Container (for example, it could be a Set, a Mapping or a Sequence). It would be nice if this could be spelled like this:
The text was updated successfully, but these errors were encountered: