Skip to content

Commit

Permalink
Trying to fix the formating of the error message for Python 3
Browse files Browse the repository at this point in the history
  • Loading branch information
Jonathan Rocher committed May 22, 2015
1 parent ab4c5a1 commit 0d4b207
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions traits/ctraits.c
Expand Up @@ -316,11 +316,22 @@ invalid_attribute_error ( PyObject * name ) {
PyTypeObject* obj_type = name->ob_type;
const char* type_name = obj_type->tp_name;
PyObject * ob_repr = PyObject_Repr(name);

#if PY_MAJOR_VERSION >= 3

const char* fmt = "attribute name must be string. Got %R (%s).";

PyErr_Format( PyExc_TypeError, fmt, ob_repr, type_name );

#else

const char* obj_repr_str = PyString_AsString(ob_repr);
const char* fmt = "attribute name must be string. Got %s (%s).";

PyErr_Format( PyExc_TypeError, fmt, obj_repr_str, type_name );

#endif

return -1;
}

Expand Down

0 comments on commit 0d4b207

Please sign in to comment.