New submission from Jeroen Demeyer <jdeme...@cage.ugent.be>:

Displaying the source code in tracebacks for Cython-compiled extension modules 
in IPython no longer works due to PEP 302. Various fixes are possible, the two 
most obvious ones are:

1. linecache should continue searching for the source file even if 
loader.get_source() returns None.

2. the method ExtensionFileLoader.get_source() should be removed (instead of 
being implemented and returning None).

Now why was this broken and how do the above fix that?

When IPython needs to display a traceback, it uses linecache.getlines() to get 
the source code to display. For Cython extensions, the filename is a correct 
*relative* filename (it must be a relative filename since Cython does not know 
where the sources will be after installation).

Since the filename is relative, linecache does not immediately find it, so it 
looks for a PEP 302 loader. For extension modules (Cython or not), it finds an 
instance of ExtensionFileLoader. If the loader has a get_source() method, then 
it uses that to get the sources. Since ExtensionFileLoader.get_source() returns 
None, linecache stops looking further for sources.

Instead, what should happen is that linecache continues looking for the sources 
in sys.path where it has a chance of finding them (if they are installed 
somewhere in sys.path).

----------
components: Library (Lib)
messages: 311829
nosy: erik.bray, jdemeyer
priority: normal
severity: normal
status: open
title: Tracebacks from Cython modules no longer work

_______________________________________
Python tracker <rep...@bugs.python.org>
<https://bugs.python.org/issue32797>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to