[Bf-python] Consistency issue

Michel Selten michel.s at home.nl
Wed Oct 1 22:10:06 CEST 2003


Hi,

yesterday, I sent a mail to the list about trying to get things
consistent in the Object module with regards to other modules - I took
the Camera module as an example.

Now that I try to actually work it all out, I come up with a small
problem. Let's take the .setLocation() method and the .loc variable in
the setAttr function for example.

When following the convention proposed in the Camera module, I should do
a:

valtuple = Py_BuildValue ("(O)", value);

and pass the valtuple result to the setLocation() function.
This is where the problem comes up. The arguments parsed in the
setLocation() function, are incompatible with the valtuple argument
passed to the setLocation() function. Here's a bit of options I can
think of:
1 - Keep it working, don't bother consistency.
    This implies not using the valtuple variable. But, reading on,
    it would also imply that the Python modules on the outside won't
    become consistent as well.
2 - Break API compatibility in the setLocation() function. The old
    call to it in a script is:
    obj.setLocation (0.0, 0.0, 0.0)
    The new call would be:
    obj.setLocation ((0.0, 0.0, 0.0))
    This option would make the setLocation function work the same
    as in the Curve module for example.
3 - Update the setLocation() function to both accept a tuple and a
    list of values. This would imply that both the following calls
    are valid in a script:
    obj.setLocation (0.0, 0.0, 0.0)
    obj.setLocation ((0.0, 0.0, 0.0))

My personal preference would go to option 3. But, there's a problem that
I'm unable to solve. Quite possibly because I'm unaware of the existance
of a Python function.
Here's what the implementation of the setLocation() function would look
like (partly):

/* parse ((0.0, 0.0, 0.0)) */
if (PyArg_ParseTuple (args, "O", &list_args))
{ ... }
/* parse (0.0, 0.0, 0.0) */
else if (PyArg_ParseTuple (args, "fff", &loc1, &loc2, &loc3))
{ ... }
else return error

The problem is that if the first if statment fails, the content of the
variable args is not available anymore. So I need to have a copy of the
variable somewhere. What's the Python call for that?

The 3rd option would make it possible to generally shift all slightly
faulty methods to the correct implementation. We can warn the user about
the deprecation of the old method in a few releases and support the new
method only after that.

What do you think?

With regards,
	Michel





More information about the Bf-python mailing list