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

Correct bogus stack-trace information after AST traversal (fixes #2) #7

Merged
merged 1 commit into from
Aug 22, 2024

Conversation

gsmecher
Copy link
Owner

We splice in AST data generated by ast.parse()ing a text block. This AST carries its own metadata (lineno and friends) associated with the injected code. When it's introspected in the process of generating a traceback, it's bogus because it doesn't correspond to lines of code in the actual ipython cell.

This PR introduces a second AST transformer that recursively copies node metadata from the original, un-transformed AST. As a result, traceback can point to the correct line of original code (even if it's not what actually got executed.)

We splice in AST data generated by ast.parse()ing a text block.  This
AST carries its own metadata (lineno and friends) associated with the
injected code. When it's introspected in the process of generating a
traceback, it's bogus because it doesn't correspond to lines of code in
the actual ipython cell.

This patch introduces a second AST transformer that recursively copies
node metadata from the original, un-transformed AST. As a result,
traceback can point to the correct line of original code (even if it's
not what actually got executed.)
@gsmecher gsmecher merged commit 40f8491 into main Aug 22, 2024
3 checks passed
@gsmecher gsmecher deleted the fix_stacktraces branch August 22, 2024 17:34
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.

1 participant