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

Gilbert, Joseph T. jgilbert at tigr.ORG
Thu Jun 1 22:03:16 CEST 2006


For simple arguments like a float value this is fine. If you want to
provide something more descriptive, use EXPP_ReturnPyObjError. I would
argue from the other side that we should provide more descriptive error
strings than "a float was expected". Otherwise yes, simply letting the
error string be set by the interpreter is fine.


-----Original Message-----
From: bf-python-bounces at projects.blender.org
[mailto:bf-python-bounces at projects.blender.org] On Behalf Of Ken Hughes
Sent: Thursday, June 01, 2006 3:36 PM
To: Blender Foundation Python list
Subject: [Bf-python] Cutting down PyArg_ParseTuple() exception verbage
andother cruft

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



_______________________________________________
Bf-python mailing list
Bf-python at projects.blender.org
http://projects.blender.org/mailman/listinfo/bf-python



More information about the Bf-python mailing list