-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
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
Fix for #1698 #1989
Fix for #1698 #1989
Conversation
These tests started to fail because the condition analyzer is now smarter and was detecting some dead code on the tests that were supposed to generate some error messages.
The code in find_instance_check was made specifically for None related checks, but the new rule is more general so it should be indipendent of strict optional checking.
Thanks for the PR! I'll take a detailed look at this early next week. |
# the left operand is the result of the operator. | ||
left_type = left_map[e.left] | ||
truthiness_restriction = true_only | ||
# type_restriction tells about the possible truth values of the left operand |
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.
I think you meant "truthiness_restriction".
Sorry for the later-than-promised review. Overall, this looks great! That said, it introduces a weird bug: x = ""
if not x:
pass
if x:
pass
else:
1 + "" # no error, indicating this branch is not typechecked/mypy thinks it can never occur I spent a little while looking into it, but it wasn't obvious where the problem was. I suspect it's related to some interaction with the |
Thanks for the thorough review, I just see it (I was on holidays). I'll try On Sat, Aug 13, 2016 at 1:35 AM, David Fisher notifications@github.com
Daniel F. Moisset - UK Country Manager |
I've added a few minor changes to fix the bug (it was a problem on |
@@ -17,6 +17,11 @@ | |||
def join_simple(declaration: Type, s: Type, t: Type) -> Type: | |||
"""Return a simple least upper bound given the declared type.""" | |||
|
|||
if (s.can_be_true, s.can_be_false) != (t.can_be_true, t.can_be_false): |
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.
We probably need this for join_types
also, right?
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.
I tried to test and couldn't make a failing case with join_type; I think
that one always creates new instances and new instances have always
undetermined boolean values. The problem with join_simple is that it was
reusing the existing types
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.
join_types
also reuses existing values in some cases. I'd expect the same problem to exist, but just be pretty hard to actually repro.
This is looking great! Just had a couple more small comments. |
OK, I found a reproduction for join_types and added a test and a fix. (and your change to true_only) |
Thanks! |
This is an implementation of my proposed fix for #1698 ( #1698 (comment) )
Relevant differences from the description there:
Type
instead of wrapping Type objects. When I want to restrict a type I make a copy and override thecan_be_true
orcan_be_false
with instance attributesnot
after realising that I couldn't find a relevant example where it helped. It's easy to add later if we discover otherwise but I didn't want to bloat an already large PRThere are some other improvements that I saw that could be made but I decided to stop here; if you think any of these are necessary I can add them:
Let me know what you think and if it's necessary to make further changes