-
Notifications
You must be signed in to change notification settings - Fork 196
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 assignment/access ordering in comprehensions #423
Conversation
Codecov Report
@@ Coverage Diff @@
## master #423 +/- ##
==========================================
+ Coverage 94.31% 94.32% +0.01%
==========================================
Files 232 232
Lines 22531 22574 +43
==========================================
+ Hits 21251 21294 +43
Misses 1280 1280
Continue to review full report at Codecov.
|
a_param = f.params.params[0].name | ||
a_param_assignment = list(scopes[a_param]["a"])[0] | ||
a_param_refs = list(a_param_assignment.references) | ||
self.assertEqual(a_param_refs, []) |
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.
Doesn't the param a
have references in the comprehensions (the last a
appear in the comprehension)?
[a for a in [] for b in a
]
[b for a in [] for b in a
]
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.
no, that last a
refers to the binding in the first for
, so it's equivalent to:
def f(a_1):
[a_2 for a_2 in [] for b_1 in a_2]
[b_2 for a_3 in [] for b_2 in a_3]
[a_5 for a_4 in [] for a_5 in []]
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.
Got it. I didn't aware the nested for loop comprehension.
[a for a in a]
is an example that I'm curious about whether it'll work fine.
The 3rd a
should be an access of the function parameter a
.
The first a
is an Access of the Assignment of the 2nd a
.
Can you also add this as a test case?
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.
Other than the comment, LGTM.
a_param = f.params.params[0].name | ||
a_param_assignment = list(scopes[a_param]["a"])[0] | ||
a_param_refs = list(a_param_assignment.references) | ||
self.assertEqual(a_param_refs, []) |
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.
Got it. I didn't aware the nested for loop comprehension.
[a for a in a]
is an example that I'm curious about whether it'll work fine.
The 3rd a
should be an access of the function parameter a
.
The first a
is an Access of the Assignment of the 2nd a
.
Can you also add this as a test case?
Summary
This change fixes attaching accesses to the right assignment in list comprehensions, so in
The
a
at the beginning of the list comprehension is now attached to thea
declared afterfor
instead of the declaration on the first line.Test Plan
Added unit tests