Description
It turns out in Python3, when using debugging, they have been a bit more strict about stopping one from using PyObject_Repr
when an exception is being handled, which sounds like a good practice as PyObject_Repr
could raise an exception. As a result, one will see an interpreter crash if an exception is already present when running PyObject_Repr
.
We use PyObject_Repr
a lot when constructing exceptions as we may want to include dtype
s or something else in the message. That being said, we need to do a better job of clearing the current exception when build the exception message. So, we need to clean up the code so that errors are cleared first by using PyErr_Clear
before constructing the new error message. If the old error message is still needed for some reason, we need to store it somewhere else before clearing.
Also, we need to do a better job at checking to see if PyObject_Repr
or similar is creating an exception. As PyObject_Repr
can raise an error, we need to make sure that we are checking to see if it errored and forwarding it on instead of continuing to construct our error message.
To see an example of how this can be solved take a look at this PR ( #6988 ).
Thanks to @seberg and @charris for helping me get the needed pieces to figure out what was going wrong here.
Below is a compiled check list of problems I have found. The line numbers are based on a commit present when this issue was opened; so, code changes in those files may have shifted them. That being said, the links will use that same commit so it is a good place to start. Feel free to add others to this issue.
-
PyArray_AssignArray
( numpy/core/src/multiarray/array_assign_array.c#L271-L284 ) -
PyArray_AssignRawScalar
( numpy/core/src/multiarray/array_assign_scalar.c#L204-L217 ) -
PyArray_FromArray
( numpy/core/src/multiarray/ctors.c#L1928-L1944 ) ( resolved in BUG: Fix dot and inner type/value exception failures #6988 ) -
convert_datetime_metadata_tuple_to_datetime_metadata
( numpy/core/src/multiarray/datetime.c#L1815-L1821 ) -
arraydescr_setstate
( numpy/core/src/multiarray/descriptor.c#L2742-L2746 ) -
array_astype
( numpy/core/src/multiarray/methods.c#L842-L856 ) -
npyiter_check_casting
( numpy/core/src/multiarray/nditer_constr.c#L1297-L1312 ) -
npyiter_check_casting
( numpy/core/src/multiarray/nditer_constr.c#L1319-L1335 ) -
PyUFunc_ValidateCasting
( numpy/core/src/umath/ufunc_type_resolution.c#L66-L80 ) -
PyUFunc_ValidateCasting
( numpy/core/src/umath/ufunc_type_resolution.c#L85-L99 ) -
PyUFunc_AdditionTypeResolver
( numpy/core/src/umath/ufunc_type_resolution.c#L748-L759 ) -
PyUFunc_SubtractionTypeResolver
( numpy/core/src/umath/ufunc_type_resolution.c#L934-L945 ) -
PyUFunc_MultiplicationTypeResolver
( numpy/core/src/umath/ufunc_type_resolution.c#L1078-L1089 ) -
PyUFunc_DivisionTypeResolver
( numpy/core/src/umath/ufunc_type_resolution.c#L1198-L1209 ) -
PyUFunc_DefaultLegacyInnerLoopSelector
( numpy/core/src/umath/ufunc_type_resolution.c#L1323-L1333 ) -
raise_binary_type_reso_error
ufunc_type_resolution.c#L72-L90
Edit: Fixed the formatting as it appears GitHub's parser's behavior changed since last creating this list.