-
-
Notifications
You must be signed in to change notification settings - Fork 3k
Better handling of compile-time relational operators #3158
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
Conversation
b = PY3 and 's' | ||
c = PY2 or 's' | ||
d = PY3 or 's' | ||
reveal_type(a) # E: Revealed type is 'builtins.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.
Shouldn't this be Union[bool, str]
? Same for all of these, really.
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.
Oh wait this is testing the special-casing for PY2 and PY3 as well. I guess it's okay. I may not get to the full review until next week.
@ilevkivskyi Could you review this? |
OK, will review this tomorrow. |
Sorry for the delays; I kinda got hung up on finals... |
NP, hope finals went/are going/will go well! |
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.
Mostly looks good to me. Just have few ideas for additional tests.
PY2 = f() | ||
PY3 = f() | ||
|
||
a = PY2 and 's' |
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 would add few more tests exchanging the order of 's'
and PY2
/PY3
. So that e.g. 's' and False == 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.
@ilevkivskyi That doesn't work, though, since infer_condition_value
doesn't take constants into account...
y = 'x' / 1 # E: Unsupported left operand type for / ("str") | ||
y | ||
|
||
|
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.
This empty line is unnecessary.
x = 'foo' | ||
else: | ||
x = 3 | ||
reveal_type(x) # E: Revealed type is 'builtins.str' |
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 would also add few more tests here and for and
, so that more combinations of True
and False
are tested.
@kirbyfan64 Are you going to continue working on this PR (here are just few tests missing and a merge conflict needs to be fixed)? |
My motherboard died. Somehow, I feel like this has been one of the craziest college years I've ever had... |
19e8556
to
3c78e82
Compare
@ilevkivskyi Done! |
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.
Thank! LGTM now.
Inspired by (but doesn't fix [yet!]) #3156. (A "fix" would to be to add an early
return
tocheck_boolean_op
ife.right_unreachable
isTrue
, but I'm not sure if that change would have other repercussions that I'm not aware of.)Now stuff like this works better: