Description
(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.