-
Notifications
You must be signed in to change notification settings - Fork 32
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: backward compatibility fix for changed source positions in 3.12.5 (#82) #83
Conversation
executing/_position_node_finder.py
Outdated
# where `iter(l)` would be otherwise the resulting node for the `iter()` call and the __iter__ call of the for implementation. | ||
# keeping the old behaviour makes it possible to distinguish both cases. | ||
|
||
return self.result.parent |
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.
It's weird that this uses self.result
instead of node
.
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.
yes you are right.
executing/_position_node_finder.py
Outdated
if ( | ||
sys.version_info >= (3, 12, 5) | ||
and instruction.opname in ("GET_ITER", "FOR_ITER") | ||
and isinstance(node, ast.For) |
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 want to return an ast.For
for these instructions, right? So isn't node
correct here? Why return its parent? I feel like I'm misunderstanding.
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.
sorry for the confusion. It was late in the evening and I messed something up while I copied the code from the other branch.
it should be isinstance(node.parent, ast.For)
I tested probably with the wrong 3.12 version. I think it would be useful to include all patch versions to the CI tests (3.8.0, ..., 3.12.0, 3.12.1, ...) but test only the short running tests. What do you think?
if ( | ||
sys.version_info >= (3, 12, 5) | ||
and instruction.opname in ("GET_ITER", "FOR_ITER") | ||
and isinstance(node.parent, ast.For) |
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.
and isinstance(node.parent, ast.For) | |
and isinstance(node.parent, ast.For) | |
and node is node.parent.iter |
What about comprehensions?
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.
They node positions for comprehensions are not affected.
class Foo:
def __iter__(self):
assert False
a = [x for x in Foo()]
output (Python 3.12.5):
Traceback (most recent call last):
File "/home/frank/projects/executing/codi.py", line 7, in <module>
a = [x for x in Foo()]
^^^^^^^^^^^^^^^^^^
File "/home/frank/projects/executing/codi.py", line 5, in __iter__
assert False
^^^^^
AssertionError
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.
Based on the apparently desired behaviour for For
, that seems like a Python bug lol
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 don't know, For
is usually a multiline statement and comprehensions are usually on a single line. I will ask 😄
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.
Thanks!
The patch/PR has been approved by the upstream maintainer: alexmojaki/executing#83 (review) Example error log: https://hydra.nixos.org/build/270409937/nixlog/2/tail
@alexmojaki can we merge this? The 3.13 branch is failing because the missing fix in 3.12. |
Yes. You should be able to merge yourself. So I will generally approve and leave you to do the merge in case you change your mind about something at the last minute. Please use "Squash and merge". |
fixes #82