[Bf-python] API refactoring considerations
Gilbert, Joseph T.
jgilbert at tigr.ORG
Wed May 31 16:03:37 CEST 2006
1) I think returning True/False is a good idea.
2) We have always clamped input to whatever the internal range is and
have not thrown an error. In theory though, it may be better to throw an
error because the user may have expected a certain result and didn't
realize that his value got clamped. All the other methods throw
AttributeError when they receive unexpected parameters. I think in this
case though we need to throw a ValueError because we have the correct
type of argument but it's the wrong value for the method.
-----Original Message-----
From: bf-python-bounces at projects.blender.org
[mailto:bf-python-bounces at projects.blender.org] On Behalf Of Ken Hughes
Sent: Tuesday, May 30, 2006 9:23 PM
To: Blender Foundation Python list
Subject: [Bf-python] API refactoring considerations
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.
_______________________________________________
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