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 inside PyRun_SimpleString() display argv[1] #53033
Comments
Hi all, I found a bug in the exception handler. When I __main__:2:DeprecationWarning: Deprecated function. When I run the app with arguments, the arguments -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[] = 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] |
Could anyone please correct the title? Thx :) |
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. |
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)
[...] |
attached a patch for this issue now. Now it first uses the name of the script, |
any news on this? |
First of all, your patch needs a test. |
Fixed in bpo-33375. commit 11a8966
|
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: