[issue15128] inspect raises exception when frames are misleading about source line numbers

Irit Katriel report at bugs.python.org
Fri Sep 18 13:30:36 EDT 2020


Irit Katriel <iritkatriel at yahoo.com> added the comment:

I think this was fixed by now:

I changed the script to print the result:

******************************************
import inspect, sys

# /etc/hostname is one line, but our source has multiple lines
code = compile('\n\n\n1/0', '/etc/hostname', 'exec')

try:
    exec(code, {})
except Exception:
    tb = sys.exc_info()[2]
else:
    assert False, "unreachable, exec should always raise exception"

# this fails with an IndexError
print(inspect.getinnerframes(tb))


******************************************

and I got this output:

C:\Users\User\src\cpython>python.bat x.py
Running Release|Win32 interpreter...
[FrameInfo(frame=<frame at 0x01140DF0, file 'C:\\Users\\User\\src\\cpython\\x.py', line 14, code <module>>, filename='C:\\Users\\User\\src\\cpython\\x.py', lineno=7, function='<module>', code_context=['    exec(code, {})\n'], index=0), FrameInfo(frame=<frame at 0x011CA758, file '/etc/hostname', line 4, code <module>>, filename='/etc/hostname', lineno=4, function='<module>', code_context=None, index=None)]

----------
nosy: +iritkatriel

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue15128>
_______________________________________


More information about the Python-bugs-list mailing list