Skip to content
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

Merged
merged 4 commits into from
Aug 25, 2024

Conversation

15r10nk
Copy link
Collaborator

@15r10nk 15r10nk commented Aug 16, 2024

fixes #82

# 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
Copy link
Owner

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.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes you are right.

if (
sys.version_info >= (3, 12, 5)
and instruction.opname in ("GET_ITER", "FOR_ITER")
and isinstance(node, ast.For)
Copy link
Owner

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.

Copy link
Collaborator Author

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)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
and isinstance(node.parent, ast.For)
and isinstance(node.parent, ast.For)
and node is node.parent.iter

What about comprehensions?

Copy link
Collaborator Author

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

Copy link
Owner

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

Copy link
Collaborator Author

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 😄

Copy link
Owner

@alexmojaki alexmojaki left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@15r10nk
Copy link
Collaborator Author

15r10nk commented Aug 24, 2024

@alexmojaki can we merge this? The 3.13 branch is failing because the missing fix in 3.12.

@alexmojaki
Copy link
Owner

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".

@15r10nk 15r10nk merged commit 230ef11 into master Aug 25, 2024
7 checks passed
@15r10nk 15r10nk deleted the fix_3.12.5 branch August 31, 2024 06:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Failure with 3.12.5
2 participants