-
Notifications
You must be signed in to change notification settings - Fork 0
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
stack_data / tracebacks #2
Comments
Ah - I see. There's some amount of "no good deed goes unpunished" associated with open-source code. I should have begun with a "thanks for your work". Also, now, thanks for your time on this little project. I had hoped ast.copy_location() would do a good job of fixing this - let me see if I can come up with something. |
gsmecher
pushed a commit
that referenced
this issue
Aug 22, 2024
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
pushed a commit
that referenced
this issue
Aug 22, 2024
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.)
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Responding to ipython/ipython#13598 (comment)
Your extension transforms
hello()
intoWhen
hello()
raises an exception, the traceback points to line 5 (await _ttemp
). But the only source code available ishello()
which only has one line.stack_data
is failing because it can't find the nonexistent source code. Nothing possibly could.Worse, if the user enters an expression that actually has 5 lines, there will be no error, the traceback will just silently point at the wrong line. I can confirm this:
A simple fix would be to define a function
maybe_await
and then always transformx
intoawait maybe_await(x)
. Then the traceback would always point to line 1 of the interactive cell (that can't go wrong) as well as to the body ofmaybe_await
making the magic less invisible and mysterious:The text was updated successfully, but these errors were encountered: