-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Make joins symmetric and transitive? #3257
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
Comments
Just an idea concerning unions and multiple inheritance. If I have two nominal types, then there are three options:
What I propose for the last case is to return |
Perhaps we could store the join as a So for example, in @ilevkivskyi case, the join of |
This idea was discussed in #3132 but it looks like this could get complicated pretty quickly. |
Closing this since nobody has come up with a feasible semantics, and the current behavior seems to be quite acceptable in practice. |
Joins don't have lattice properties with multiple inheritance. Here is an example of where things currently aren't right because joins aren't symmetric:
Similar examples can we found for transitivity, I believe -- changing the order of things in a list causes a different type to be inferred, which is at least somewhat bad, as it makes mypy feel unpredictable in some cases.
One option would be to only follow the first/leftmost base class in case of multiple inheritance, so the both results would be
List[object]
. We can tweak the example to work it consistently while producing useful types:Though theoretically better, it has some issues:
Alternatively, we could just not care about lattice properties. I think that joins only affect inferred types and they won't cause a runtime safety issue since we check types after inference. However, we should review all uses of joins in the implementation and try to understand what the implications would be.
Another fix would be to generate more union types from joins, but that would likely have a bigger effect. Now that union types aren't as buggy as they used to be, this might be at least worth some experimentation.
This issue also affects protocols (#3132), and there the situation is much more complicated.
The text was updated successfully, but these errors were encountered: