You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
assignee=Noneclosed_at=<Date2018-06-09.17:10:30.972>created_at=<Date2018-04-27.16:38:55.779>labels= ['3.8', 'library']
title='warnings: get filename from frame.f_code.co_filename'updated_at=<Date2019-10-22.23:03:40.665>user='https://github.com/takluyver'
The warnings module tries to find and show the line of code which is responsible for a warning, for the same reasons that tracebacks show a line of code from each stack frame. However, they work in quite different ways.
Native tracebacks, the traceback module and pdb all do something like this:
But warnings does something like this (paraphrasing C code in _warnings.c):
This causes problems for interactive interpreters like IPython, because there are multiple pieces of entered code which have to share the same global namespace. E.g. ipython/ipython#11080
This was raised a long time ago in bpo-1692664. Back then, the answer was that co_filename could be wrong if the path of a pyc file changed. However, that issue was fixed in bpo-1180193. And it seems that the co_filename approach must largely work today, because tracebacks and pdb rely on it.
So I'm proposing to make warnings match how those other tools find filenames. I think this should also be a minor simplification of the code.