Issue33375
Created on 2018-04-27 16:38 by takluyver, last changed 2019-10-22 23:03 by vstinner. This issue is now closed.
| Pull Requests | |||
|---|---|---|---|
| URL | Status | Linked | Edit |
| PR 6622 | merged | takluyver, 2018-04-28 06:06 | |
| PR 7556 | merged | ZackerySpytz, 2018-06-09 07:06 | |
| Messages (9) | |||
|---|---|---|---|
| msg315848 - (view) | Author: Thomas Kluyver (takluyver) * | Date: 2018-04-27 16:38 | |
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. https://github.com/ipython/ipython/issues/11080
This was raised a long time ago in #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 #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.
|
|||
| msg316133 - (view) | Author: Thomas Kluyver (takluyver) * | Date: 2018-05-03 19:52 | |
Hi Brett! If you get a moment, any review of the linked PR would be welcome. :-) https://github.com/python/cpython/pull/6622 |
|||
| msg316134 - (view) | Author: Brett Cannon (brett.cannon) * | Date: 2018-05-03 19:56 | |
I just added myself to review the PR. At worst I will get to it during the sprints at PyCon US. On Thu, 3 May 2018 at 12:52 Thomas Kluyver <report@bugs.python.org> wrote: > > Thomas Kluyver <thomas@kluyver.me.uk> added the comment: > > Hi Brett! If you get a moment, any review of the linked PR would be > welcome. :-) > > https://github.com/python/cpython/pull/6622 > > ---------- > > _______________________________________ > Python tracker <report@bugs.python.org> > <https://bugs.python.org/issue33375> > _______________________________________ > |
|||
| msg316135 - (view) | Author: Thomas Kluyver (takluyver) * | Date: 2018-05-03 20:11 | |
Thanks! No rush, I just thought I'd take the opportunity when you added yourself to the nosy list. |
|||
| msg319099 - (view) | Author: Brett Cannon (brett.cannon) * | Date: 2018-06-08 19:28 | |
New changeset 11a896652ee98aa44e59ed25237f9efb56635dcf by Brett Cannon (Thomas Kluyver) in branch 'master': bpo-33375: Get filename for warnings from frame.f_code.co_filename (GH-6622) https://github.com/python/cpython/commit/11a896652ee98aa44e59ed25237f9efb56635dcf |
|||
| msg319161 - (view) | Author: Brett Cannon (brett.cannon) * | Date: 2018-06-09 17:09 | |
New changeset 3f45f5da8eb052f1b54d37086c67b7094f35b67b by Brett Cannon (Zackery Spytz) in branch 'master': bpo-33375: Fix GCC warning in Python/_warnings.c (GH-7556) https://github.com/python/cpython/commit/3f45f5da8eb052f1b54d37086c67b7094f35b67b |
|||
| msg319162 - (view) | Author: Brett Cannon (brett.cannon) * | Date: 2018-06-09 17:10 | |
Thanks everyone for making this happen! |
|||
| msg320045 - (view) | Author: STINNER Victor (vstinner) * | Date: 2018-06-20 10:00 | |
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! https://mail.python.org/pipermail/python-committers/2017-June/004564.html |
|||
| msg355172 - (view) | Author: STINNER Victor (vstinner) * | Date: 2019-10-22 23:03 | |
I closed bpo-8787 as a duplicate of this issue. |
|||
| History | |||
|---|---|---|---|
| Date | User | Action | Args |
| 2019-10-22 23:03:40 | vstinner | set | messages:
+ msg355172 versions: + Python 3.8 |
| 2019-10-22 23:03:21 | vstinner | link | issue8787 superseder |
| 2018-06-20 10:00:32 | vstinner | set | nosy:
+ vstinner messages: + msg320045 |
| 2018-06-09 17:10:30 | brett.cannon | set | status: open -> closed resolution: fixed messages: + msg319162 stage: patch review -> resolved |
| 2018-06-09 17:09:48 | brett.cannon | set | messages: + msg319161 |
| 2018-06-09 07:06:33 | ZackerySpytz | set | pull_requests: + pull_request7190 |
| 2018-06-08 19:28:39 | brett.cannon | set | messages: + msg319099 |
| 2018-05-03 20:11:21 | takluyver | set | messages: + msg316135 |
| 2018-05-03 19:56:42 | brett.cannon | set | messages: + msg316134 |
| 2018-05-03 19:52:11 | takluyver | set | messages: + msg316133 |
| 2018-04-30 18:34:56 | brett.cannon | set | nosy:
+ brett.cannon |
| 2018-04-28 06:06:28 | takluyver | set | keywords:
+ patch stage: patch review pull_requests: + pull_request6318 |
| 2018-04-27 16:38:55 | takluyver | create | |