cknd / stackprinter

Debugging-friendly exceptions for Python
MIT License
1.28k stars 37 forks source link

Catch wrong linenos #46

Open cknd opened 3 years ago

cknd commented 3 years ago

Catch an (crashing #45 ) edge case where the frame's current line numer is wrong, or the discoverd line number where the frame's code block starts is. This looks like a python bug or an inspect.getsource bug -- OR a getsource bug that is ultimately a python bug, because inspect just uses frame.f_code.co_firstlineno (= the frame's own reported beginning of its code block), and I can't imagine a situation where that can legitimately not contain frame.f_lineno.

I deal with this here by showing a warning in-band that the line number can't be 100% trusted, while also moving the active line shown down to the first available source line.

(Not completely happy with that solution, of course)