[Bf-committers] python mathutils api update proposal

Campbell Barton ideasman42 at gmail.com
Fri Feb 4 01:47:12 CET 2011


On Fri, Feb 4, 2011 at 12:28 AM, Dan Eicher <dan at trollwerks.org> wrote:
> On Thu, Feb 3, 2011 at 2:54 PM, Campbell Barton <ideasman42 at gmail.com> wrote:
>
>> -- snip --
>>
>> To see what I mean about sloppy argument parsing, see comparison of
>> 2.4x and 2.5x code below - both the same function though 2.5x uses
>> mathutils_array_parse() utility function.
>> The 2.4x code even had a memory leak for some time (refcount error).
>>
>> # --- 2.5x Code
>> -- snip --
> It's actually pretty easy to do this type of overloading, you just
> need python to do the heavy lifting through
> PyArg_ParseTuple[AndKeywords]. Pybindgen uses this method in its
> generated code and it works very well.
>
> The gist -- multiple functions that the main method calls and once it
> finds one that doesn't throw an exception (from function args not
> matching) then that's the one it uses. The code is nicely separated so
> you don't end up with a bunch of if else blocks and everyone is happy.
>
> I would be simpler to just show some code than describe it methinks
>
> Dan

As Alex suggests, keywords only args could be used in this case:
Euler(x, y, x, order='XZY')
I don't see this as especially better or worse, just different, but
I'm also not interested to change.

I've seen PyArg_ParseTuple[AndKeywords] used as you suggest but I
rather not depend on python exceptions for argument parsing with
constructors, this would give noticeable slowdown if defining
mathutils types in a loop.


More information about the Bf-committers mailing list