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

Feature suggestion: Fall back to line-level traces if AST is unavailable #21

Closed
collares opened this issue Feb 11, 2022 · 3 comments
Closed

Comments

@collares
Copy link

collares commented Feb 11, 2022

(I may be completely wrong in my analysis here, apologies in advance!)

I recently saw a regression in IPython 8 which I believe is due to stack_data. To illustrate the situation, I have adapted an example from ipython/ipython#6300. Save this to a file called cythontest.pyx:

cdef list foo = []

def f():
    raise ValueError('message')

and run this under IPython (pyximport is part of Cython):

import pyximport
pyximport.install(reload_support=True)
import cythontest
cythontest.f()

IPython 7 does show the following (great!) traceback:

---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-1-c52676a06430> in <module>
      4 import cythontest
      5 
----> 6 cythontest.f()

~/cythontest.pyx in cythontest.f()
      2 
      3 def f():
----> 4     raise ValueError('message')

ValueError: message

IPython 8, however, does not show the source code for cythontest.f:

---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
Input In [3], in <module>
      3 pyximport.install(reload_support=True)
      4 import cythontest
----> 6 cythontest.f()

File ~/cythontest.pyx:4, in cythontest.f()

ValueError: message

I believe this happens because IPython 8 depends on this repository's package (stack_data), which tries to parse the pyx file and fails to produce an AST because Cython is a superset of Python. Given that we have line number information and the pyx file is valid source code (just not Python source code), I believe it would be better for the user if the relevant source fragment were printed even in cases where the AST is not available, similar to what IPython 7 does.

@alexmojaki
Copy link
Owner

You're completely right, I don't know why I didn't do this in the first place.

alexmojaki added a commit that referenced this issue Feb 14, 2022
Fallback to basic Source.pieces when there is no Source.tree. Fixes #21
@alexmojaki
Copy link
Owner

OK, pip install -U stack_data and give it a go!

@collares
Copy link
Author

Thank you! https://trac.sagemath.org/ticket/33170#comment:9 confirms this is working for the Sagemath use-case too.

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

No branches or pull requests

2 participants