[issue1692664] warnings.py gets filename wrong for eval/exec

Thomas Kluyver report at bugs.python.org
Fri Apr 27 09:54:50 EDT 2018


Thomas Kluyver <thomas at kluyver.me.uk> added the comment:

Time for some bug archaeology!

The reason given for not using frame.f_code.co_filename for warnings was that it can be wrong when the path of .pyc files changes. However, it looks like that was fixed in #1180193 (thanks for the pointer zseil), so I'd like this idea to be reconsidered.

Python uses frame.f_code.co_filename for tracebacks and in pdb, so it's counterintuitive that the warnings module works differently. They are all trying to do the same thing: find and show the bit of code that you're interested in.

This causes problems in IPython with warnings attributed to interactive code: warnings sees it all as part of the __main__ module, so we can't distinguish which input it's pointing to (it's usually obvious, but still...). We have integrated with linecache to make tracebacks work, and I think that if warnings used code.co_filename, it would also work as expected.

----------
nosy: +takluyver

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


More information about the Python-bugs-list mailing list