Skip to content

Commit

Permalink
refactor: review changes
Browse files Browse the repository at this point in the history
  • Loading branch information
15r10nk committed Aug 18, 2024
1 parent 3c5ae43 commit 1e09e27
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions executing/_position_node_finder.py
Original file line number Diff line number Diff line change
Expand Up @@ -221,13 +221,13 @@ def fix_result(
if (
sys.version_info >= (3, 12, 5)
and instruction.opname in ("GET_ITER", "FOR_ITER")
and isinstance(node, ast.For)
and isinstance(node.parent, ast.For)
):
# node positions have changed in 3.13
# https://github.com/python/cpython/issues/93691#event-13151024246
# node positions have changed in 3.12.5
# https://github.com/python/cpython/issues/93691
# `for` calls __iter__ and __next__ during execution, the calling
# expression of these calls was the ast.For node since cpython 3.11 (see test_iter).
# cpython 3.13 changed this to the `iter` node of the loop, to make tracebacks easier to read.
# cpython 3.12.5 changed this to the `iter` node of the loop, to make tracebacks easier to read.
# This keeps backward compatibility with older executing versions.

# there are also cases like:
Expand All @@ -237,7 +237,7 @@ def fix_result(
# 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
return node.parent
return node

def known_issues(self, node: EnhancedAST, instruction: dis.Instruction) -> None:
Expand Down

0 comments on commit 1e09e27

Please sign in to comment.