[Bf-python] Cutting down PyArg_ParseTuple() exception verbage and other cruft

Ken Hughes khughes at pacific.edu
Thu Jun 1 21:36:21 CEST 2006


I'm sifting through all +6K lines of Object.c to verify line-by-line I'm 
not messing up anything, and can't help but notice a lot of lines like this:

     if( !PyArg_ParseTuple( args, "f", &value ) )
         return EXPP_ReturnPyObjError( PyExc_TypeError,
             "expected float argument" );

This bascially does the same thing as:
     if( !PyArg_ParseTuple( args, "f", &value ) )
         return NULL;

The latter prints:
TypeError: a float is required

Since our original message isn't giving any more real information, how 
about we just use the internal exceptions in these simple cases?

Same goes for:

     attr = PyFloat_FromDouble( ( double ) value );
     if( attr )
         return attr;
     return EXPP_ReturnPyObjError( PyExc_RuntimeError,
                     "couldn't get value" );

Replace with:

     return PyFloat_FromDouble( ( double ) value );

Grokking the Python source indicates we get PyErr_NoMemory() on error 
anyway, which is just about as useful an error message.

Ken






More information about the Bf-python mailing list