[Bf-python] Python 2.2 Type API changes

Joseph Gilbert models at paposo.com
Mon Jul 19 03:09:40 CEST 2004


Looks interesting. My only complaint is that it assumes that you always have
a function to call for geattr/setattr variables. I guess this would mean
spliting the getattr and seattr members into a bunch of functions. It looks
cleaner than the current implementation (although maybe a bit more
confusing).

-----Original Message-----
From: bf-python-admin at blender.org [mailto:bf-python-admin at blender.org]On
Behalf Of Yann Vernier
Sent: Sunday, July 18, 2004 6:26 PM
To: Blender Foundation Python list
Subject: [Bf-python] Python 2.2 Type API changes


Since Python 2.2, it has been possible to pass attributes in the form of
two lists - one for simple structure members, tp_members, and one for
those requiring functions to define their behaviour, tp_getset. These
fields come right after tp_methods. Together, they make the long lists
of string tests in getattr/setattr unnecessary, which I think must be an
advantage. No need to write a separate list of available attributes for
dir(), and try reading object.EffZoinks to see what slight assumptions
can do. It's also possible to subclass types if written right.

Unfortunately, this interface comes with poor examples and less
documentation. One copy of the example is at
http://python.active-venture.com/ext/node23.html

I've written a partial conversion of Object.c, diff at:
http://donkey.dyndns.org/~yann/blender/Object.c.diff1

Note that the use of PyType_Ready is required. This diff only exchanges
getattr for a getset list; setattr is untouched but can be similarly
converted. Sorry about the macros, I just got too tired of copying the
same stuff.

Again I ran into a crash bug in the original:
 Object_CreatePyObject does not check for NULL. getattr(track)
 didn't, either. Reading object.track in Python for an object
 which is not tracking crashed Blender.

--
PGP fingerprint = 9242 DC15 2502 FEAB E15F  84C6 D538 EC09 5380 5746




More information about the Bf-python mailing list