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
C/API PyErr_AsUnicode() #50533
Comments
This function returns the output of PyErr_Print as a unicode string. We needed this in Blender3D because it has its own error logging system The patch is made against python3k r73429. |
last patch was bad heres a new one. |
PyErr_Print seems a too high-level function for this usage:
I'd prefer a function similar to PyErr_Display. And sys.stderr should As for the Blender use case: isn't it appropriate for Blender to change |
Thanks for the feedback, I wasnt aware of PyErr_Display, its not http://docs.python.org/dev/py3k/genindex-all.html For blender, its development id still in progress so we don't yet have however we use a number of python apis in blender (game engine api, UI Ill look into using a PyErr_DisplayEx |
Updated with an PyErr_DisplayEx function that accepts a file argument. |
+ PyErr_Fetch(&error_type, &error_value, &error_traceback); I think that the call to PyErr_Clear() is useless, PyErr_Fetch() already cleared the exception. + /* clear the error */ Why do you restore the error if you clear it directly? I think that at this position, there is no current exception. So it may be simplified as: Py_DECREF(error_type);
Py_DECREF(error_value);
Py_DECREF(error_traceback); I suppose here that all these 3 variables are not NULL. + if(! (string_io_mod= PyImport_ImportModule("io")) ) { Minor style remark: you can remove the "else" keywords here. You should factorize the error handling at the end using "goto error;" with a error handler looking like: error:
PyErr_Clear();
Py_CLEAR(stringio_buf);
finally:
Py_XDECREF(string_io_mod);
Py_XDECREF(string_io);
Py_XDECREF(string_io_getvalue);
return NULL; In my opinion, it's easier to maintain it, and more readable. |
/* Returns the exception string as a new NULL is not very useful to analyze the error :-/ Why don't keep errors if the conversion failed? The caller will be responsible to use the new error, or to clear it. If PyErr_AsUnicode() raises a new error on conversion error, you should raise an error on: + if (!PyErr_Occurred()) On keep PyImport_ImportModule(), PyObject_CallMethod() and PyObject_GetAttrString() error. Oh, by the way, PyErr_AsUnicode returns NULL and raise an error if PyObject_CallObject() failed (if StringIO().getvalue() failed). |
There should also be a call to |
@ideasman42 This issue is quite old. Do you still need this feature? Marking as pending and will close this issue if there is no movement on it soon. |
@iritkatriel yes, I see there have been replies to the patch I must have missed, so I'll attempt to update the patch based on feedback. |
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: