Message315848
| Author |
takluyver |
| Recipients |
takluyver |
| Date |
2018年04月27日.16:38:55 |
| SpamBayes Score |
-1.0 |
| Marked as misclassified |
Yes |
| Message-id |
<1524847135.79.0.682650639539.issue33375@psf.upfronthosting.co.za> |
| In-reply-to |
| Content |
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. |
|
History
|
|---|
| Date |
User |
Action |
Args |
| 2018年04月27日 16:38:55 | takluyver | set | recipients:
+ takluyver |
| 2018年04月27日 16:38:55 | takluyver | set | messageid: <1524847135.79.0.682650639539.issue33375@psf.upfronthosting.co.za> |
| 2018年04月27日 16:38:55 | takluyver | link | issue33375 messages |
| 2018年04月27日 16:38:55 | takluyver | create |
|