diff --git a/src/wrapper/_pvt_struct_v2.cpp b/src/wrapper/_pvt_struct_v2.cpp index f0762c625d7b295e13870a4f6ac9561c4f8a86fa..23a407812c9ee95c92c647f2072c3a26117c7530 100644 --- a/src/wrapper/_pvt_struct_v2.cpp +++ b/src/wrapper/_pvt_struct_v2.cpp @@ -757,22 +757,16 @@ np_complex_float(char *p, PyObject *v, const formatdef *f) float im = 0.0f; Py_complex cplx; #if (PY_VERSION_HEX < 0x02060000) + if (PyComplex_Check(v)) + cplx = PyComplex_AsCComplex(v); + else if (PyObject_HasAttrString(v, "__complex__")) { - if (PyComplex_Check(v)) - cplx = PyComplex_AsCComplex(v); - else if (PyObject_HasAttrString(v, "__complex__")) - { - PyObject *v2 = PyObject_CallMethod(v, "__complex__", ""); - cplx = PyComplex_AsCComplex(v2); - Py_DECREF(v2); - } - else - { - PyErr_SetString(StructError, - "required argument is not a complex"); - return -1; - } + PyObject *v2 = PyObject_CallMethod(v, "__complex__", ""); + cplx = PyComplex_AsCComplex(v2); + Py_DECREF(v2); } + else + cplx = PyComplex_AsCComplex(v); #else cplx = PyComplex_AsCComplex(v); #endif @@ -807,22 +801,16 @@ np_complex_double(char *p, PyObject *v, const formatdef *f) double im = 0.0; Py_complex cplx; #if (PY_VERSION_HEX < 0x02060000) + if (PyComplex_Check(v)) + cplx = PyComplex_AsCComplex(v); + else if (PyObject_HasAttrString(v, "__complex__")) { - if (PyComplex_Check(v)) - cplx = PyComplex_AsCComplex(v); - else if (PyObject_HasAttrString(v, "__complex__")) - { - PyObject *v2 = PyObject_CallMethod(v, "__complex__", ""); - cplx = PyComplex_AsCComplex(v2); - Py_DECREF(v2); - } - else - { - PyErr_SetString(StructError, - "required argument is not a complex"); - return -1; - } + PyObject *v2 = PyObject_CallMethod(v, "__complex__", ""); + cplx = PyComplex_AsCComplex(v2); + Py_DECREF(v2); } + else + cplx = PyComplex_AsCComplex(v); #else cplx = PyComplex_AsCComplex(v); #endif