J
Jeff McNeil
Hi all,
In an effort to get (much) better at writing Python code, I've been
trying to follow and document what the interpreter does from main in
Modules/python.c up through the execution of byte code. Mostly for my
own consumption and benefit, but I may blog it if it turns out half
way decent.
Anyways, I've been going through PyType_Ready as it sets up copies of
PyObjectType, and I'm a bit confused by tp_base, ob_type, and
tp_bases. I've been using http://docs.python.org/c-api/index.html as
a guideline.
So, the documentation states that ob_type is a pointer to the type's
type, or metatype. Rather, this is a pointer to the new type's
metaclass?
Next, we have tp_base. That's defined as "an optional pointer to a
base type from which type properties are inherited." The value of
tp_base is then added to the tp_bases tuple. This is confusing me. On
the surface, it sound as though they're one in the same?
I *think* (and dir() of a subclass of type seems to back it up), that
tp_base is only at play when the object in question inherits from
type?
I've tried Googling around a bit. Perhaps it's better documented
somewhere? Or perhaps someone can give me a quick explanation?
Thanks!
Jeff
In an effort to get (much) better at writing Python code, I've been
trying to follow and document what the interpreter does from main in
Modules/python.c up through the execution of byte code. Mostly for my
own consumption and benefit, but I may blog it if it turns out half
way decent.
Anyways, I've been going through PyType_Ready as it sets up copies of
PyObjectType, and I'm a bit confused by tp_base, ob_type, and
tp_bases. I've been using http://docs.python.org/c-api/index.html as
a guideline.
So, the documentation states that ob_type is a pointer to the type's
type, or metatype. Rather, this is a pointer to the new type's
metaclass?
Next, we have tp_base. That's defined as "an optional pointer to a
base type from which type properties are inherited." The value of
tp_base is then added to the tp_bases tuple. This is confusing me. On
the surface, it sound as though they're one in the same?
I *think* (and dir() of a subclass of type seems to back it up), that
tp_base is only at play when the object in question inherits from
type?
I've tried Googling around a bit. Perhaps it's better documented
somewhere? Or perhaps someone can give me a quick explanation?
Thanks!
Jeff