-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
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
Empty list unification #1403
Empty list unification #1403
Conversation
(Note, this branches off #1402 but it's really independent from that.) |
FWIW I racked my brain but I have not come up with an example where both the context and the order of evaluation (left-first or right-first) matter. In all cases I can think of, if a context is provided at all, either |
Here's something suggesting that maybe I'm not going far enough?
The errors are:
I would expect EDIT That's not new behavior -- it's just because the else-clause is analyzed using the type of the if-clause as context, and that was always there. However in this case my code to reverse the roles doesn't trigger because |
My intuition just wants to try both versions always: (a) analyze the if-clause first and use it as the context to analyze the else-clause; (b) the reverse; and then (c) use the best of the two, reporting only the errors from the winner. But I don't have a good intuition for how to judge the best result -- it could be the one with the least errors, or the one that isn't |
@@ -1502,6 +1521,19 @@ def not_ready_callback(self, name: str, context: Context) -> None: | |||
self.chk.handle_cannot_determine_type(name, context) | |||
|
|||
|
|||
# TODO: What's a good name for this function? | |||
def has_unfinished_types(t: Type) -> bool: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is a similar function already in checker.py
: is_valid_inferred_type
. You can probably use it instead of this.
If we do it always both ways, we could pick the result where the result of the join is the most specific ( Here are three more ideas for the
This problem is actually more general. For example, consider this code (I'm not suggesting to fix this now, but giving this as additional context):
|
Now we can use `with binder: X` instead of `binder.push_frame(); X; binder.pop_frame()`
…as an empty list/set/dict. Fix #1094.
1d2a30d
to
e20d469
Compare
I've addressed your low-level review nits and refactored the code a bit, but I'm not making any progress on the [0]...[0.0] issue, and I propose to give up on that for now. I'll file it as a new issue we can address for a later release. |
Makes sense -- the |
There are three TODOs left:
([x] if ... else [])
(and that works with the limited test fixtures)