-
-
Notifications
You must be signed in to change notification settings - Fork 30.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
warnings: get filename from frame.f_code.co_filename #77556
Comments
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: frame.f_code.co_filename But warnings does something like this (paraphrasing C code in _warnings.c): frame.f_globals.get('__file__', sys.argv[0]) 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. |
Hi Brett! If you get a moment, any review of the linked PR would be welcome. :-) |
I just added myself to review the PR. At worst I will get to it during the On Thu, 3 May 2018 at 12:52 Thomas Kluyver <report@bugs.python.org> wrote:
|
Thanks! No rush, I just thought I'd take the opportunity when you added yourself to the nosy list. |
New changeset 3f45f5d by Brett Cannon (Zackery Spytz) in branch 'master': |
Thanks everyone for making this happen! |
This change introduced a regression: bpo-33912 "[EASY] test_warnings: test_exec_filename() fails when run with -Werror". I consider that it's an easy issue, please don't fix it, but explain how to fix it and let a newcomer to fix it! |
I closed bpo-8787 as a duplicate of this issue. |
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
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: