[Bf-python] API refactoring considerations

Ken Hughes khughes at pacific.edu
Wed May 31 03:22:35 CEST 2006


As I' working on the Object.c tp_getset switchover, two questions came 
up which I think would be nice to decide (a) prior to the API refactor 
and (b) hopefully before I finish working on this module:***

(1) We decided around the 2.40 release that attribute setters should be 
as forgiving as possible, for example using PyObject_IsTrue() to 
evaluate things boolean.  Well, since True/False are coerced internally 
to integers when you say things like "if True==1:" and "y=True+1", maybe 
it's time to start having attribute getters returning boolean when they 
really are booleans?
(2) I was about to start range checking attribute setters.  My 
rule-of-thumb (or maybe it really is the rule) is that if the UI clamps 
the input (for something a slider) then I use EXPP_ClampX(), otherwise I 
check for explicit inputs (like for a menu or bitfield) and throw an 
exception if the value lies outside the range.  After something Stephen 
said a few weeks back about armature.setName() -- which if the name is 
already used creates a different name but doesn't throw an exception -- 
I realize EXPP_ClampX() is a similar situation.  So should the API clamp 
inputs or should it throw exceptions in this case?

Ken

***and by the way, 
http://mediawiki.blender.org/index.php/BlenderDev/Bitfields still would 
appreciate your comments.



More information about the Bf-python mailing list