[Bf-python] tp_getset update & TypeObjects

Gilbert, Joseph jgilbert at tigr.ORG
Thu Aug 11 17:21:42 CEST 2005


The way to access the doc string of a TypeObject attriubute is:

Print TypeObject.attribute.__doc__

Which leads me into another point regarding the use of typeobjects in
the api... :)
A TypeObject is the same thing as a 'class' in python. The way type
objects are implemented prob. needs some attention. 

myInstance = Package.Module.TypeObject(key='value')
Is the same thing as:

class TypeObject:
...def __init__(self, key=value):
......(do x and return)
myInstance = TypeObject(key='value')

However, for this to work (as in the cAPI) you need to override the
tp_new and tp_init pointer of the typeobject at least so you can do the
initialization there. Currently we use 'factory functions' like
Module.New() to do this. (although this may be good for object you don't
way people calling __new__() on :)) If you call
Blender.Types.TypeObject() your guaranteed to get the wrong (not
initialized correctly) object back.

Imho it would be better to register the TypeObjects in their respective
modules. That way you can do stuff like this:
If v == Blender.Module.TypeObject
X = Blender.Module.TypeObject(initalizers)
Print Blender.Module.TypeObject.attribute.__doc__

Currently the Armature module is going in this direction (but will be
backwards compatible - New() can wrap the tp_new method override. And
TypeObject will be added to Types)

This is the secret: :p
If (PyType_Ready(&TypeObject) < 0)
...return Py_None

Py_INCREF(&TypeObject)
PyModule_AddObject(module, "myTypeObject", (PyObject*)&TypeObject)

The PyType_Ready obviates the need for doing:

myTypeObject.ob_type = &TypeObject

in types.c because PyType_Ready() does this and returns when the
interpreter starts up before any classes are initialized.

Anyway sorry for the blather. :))


-----Original Message-----
From: bf-python-bounces at projects.blender.org
[mailto:bf-python-bounces at projects.blender.org] On Behalf Of Yehoshua
Sapir
Sent: Wednesday, August 10, 2005 4:12 AM
To: Blender Foundation Python list
Subject: Re: [Bf-python] tp_getset update


>     (3) does anyone have an idea how the doc field in the tp_getset is
> accessed?  For example:
>
>          {"bias",
>          (getter)Lamp_getBias, (setter)Lamp_setBias,
>          "Lamp shadow map sampling bias",
>          NULL},
>
> If I try "print lamp.bias.__doc__" I get a doc string explaining how 
> to use a float (which is the type of "bias").  I haven't found 
> anything in the Python docs which explain how to access this field; 
> maybe it isn't implemented yet?

help(lamp) and help(lamp.bias) work.
_______________________________________________
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