This issue tracker has been migrated to GitHub ,
and is currently read-only.
For more information,
see the GitHub FAQs in the Python's Developer Guide.
Created on 2010年05月22日 14:00 by Sebastian, last changed 2022年04月11日 14:57 by admin. This issue is now closed.
| Files | ||||
|---|---|---|---|---|
| File name | Uploaded | Description | Edit | |
| _warnings.c.patch | Sebastian, 2010年05月25日 15:36 | |||
| Messages (8) | |||
|---|---|---|---|
| msg106306 - (view) | Author: Sebastian (Sebastian) | Date: 2010年05月22日 14:00 | |
Hi all, I found a bug in the exception handler. When I start the app without any arguments I get an output I expect: __main__:2:DeprecationWarning: Deprecated function. When I run the app with arguments, the arguments are printed somehow in the exception output: -test=HALLO:1:DeprecationWarning: Deprecated function Can anyone please confirm? Bye, Seb [code] #include "Python/Python.h" static PyObject *testfunc(PyObject *self, PyObject *args, PyObject *keywords) { PyErr_Warn(PyExc_DeprecationWarning, "Deprecated function."); Py_RETURN_NONE; } static PyMethodDef testmod[] = { {"testfunc", (PyCFunction)testfunc, METH_NOARGS, "Prints out a text to stdout."}, {NULL} }; int main (int argc, char **argv) { Py_Initialize(); PySys_SetArgv(argc, argv); PyObject *mod = Py_InitModule4("testmod", testmod, "", NULL, PYTHON_API_VERSION); if(mod == NULL) return -1; PyRun_SimpleString( "import testmod\n" "testmod.testfunc()"); Py_Finalize(); return 0; } [/code] |
|||
| msg106307 - (view) | Author: Sebastian (Sebastian) | Date: 2010年05月22日 14:02 | |
Could anyone please correct the title? Thx :) |
|||
| msg106417 - (view) | Author: Amaury Forgeot d'Arc (amaury.forgeotdarc) * (Python committer) | Date: 2010年05月25日 08:04 | |
Yes, the warnings module tries to display the file name. Inside PyRun_SimpleString(), globals()['__name__'] == '__main__', and the warnings module supposes that argv[1] is the name of the script. I wonder whether __file__ would be more accurate: it is filled when running a script, but not when running a string. And sys.argv would not be used any more. |
|||
| msg106419 - (view) | Author: Sebastian (Sebastian) | Date: 2010年05月25日 08:33 | |
Oh, damn. I really forgot the argv filename thing. Nevermind :) But back to topic. __file__ might be not the best solution for that. What does Python when embedded, and __file__ is not set? That can happen when the source of your code is not a file (multiline textbox, ...) I would simply follow the way how the traceback solves this. Just print out the filename passed to: Py_CompileStringFlags(const char *str, const char *filename, int start, PyCompilerFlags *flags) PyRun_SimpleFileExFlags(FILE *fp, const char *filename, int closeit, PyCompilerFlags *flags) [...] |
|||
| msg106442 - (view) | Author: Sebastian (Sebastian) | Date: 2010年05月25日 15:36 | |
attached a patch for this issue now. Now it first uses the name of the script, instead of __file__. |
|||
| msg106783 - (view) | Author: Sebastian (Sebastian) | Date: 2010年05月30日 23:26 | |
any news on this? |
|||
| msg106784 - (view) | Author: Benjamin Peterson (benjamin.peterson) * (Python committer) | Date: 2010年05月31日 00:42 | |
First of all, your patch needs a test. |
|||
| msg355171 - (view) | Author: STINNER Victor (vstinner) * (Python committer) | Date: 2019年10月22日 23:03 | |
Fixed in bpo-33375. commit 11a896652ee98aa44e59ed25237f9efb56635dcf Author: Thomas Kluyver <takowl@gmail.com> Date: Fri Jun 8 21:28:37 2018 +0200 bpo-33375: Get filename for warnings from frame.f_code.co_filename (GH-6622) More consistent with how other parts of Python find the filename (e.g. tracebacks and pdb). |
|||
| History | |||
|---|---|---|---|
| Date | User | Action | Args |
| 2022年04月11日 14:57:01 | admin | set | github: 53033 |
| 2019年10月22日 23:03:21 | vstinner | set | superseder: warnings: get filename from frame.f_code.co_filename resolution: fixed -> duplicate |
| 2019年10月22日 23:03:09 | vstinner | set | status: open -> closed nosy: + vstinner messages: + msg355171 resolution: fixed stage: resolved |
| 2012年11月17日 17:47:11 | brett.cannon | set | nosy:
- brett.cannon |
| 2010年09月27日 20:59:58 | brett.cannon | set | assignee: brett.cannon -> |
| 2010年05月31日 00:42:54 | benjamin.peterson | set | nosy:
+ benjamin.peterson messages: + msg106784 |
| 2010年05月30日 23:26:51 | Sebastian | set | messages: + msg106783 |
| 2010年05月25日 15:36:09 | Sebastian | set | files:
+ _warnings.c.patch keywords: + patch messages: + msg106442 |
| 2010年05月25日 08:33:43 | Sebastian | set | messages: + msg106419 |
| 2010年05月25日 08:04:30 | amaury.forgeotdarc | set | title: PySys_Get -> warnings inside PyRun_SimpleString() display argv[1] nosy: + amaury.forgeotdarc, brett.cannon messages: + msg106417 assignee: brett.cannon |
| 2010年05月22日 14:02:47 | Sebastian | set | messages: + msg106307 |
| 2010年05月22日 14:00:30 | Sebastian | create | |