C API for new-style classes

Aahz aahz at pythoncraft.com
Thu Jun 10 18:24:35 EDT 2004


In article <pan.2004.06.05.09.18.17.76354.23710 at somethinglike.sbcglobalDOTnet>,
Eric Wilhelm  <ewilhelm at somethinglike.sbcglobalDOTnet> wrote:
>
>By new-style classes, I'm referring to the changes which came into 2.2 as
>a result of PEP 252 and 253.  I discovered this problem when trying to
>use the Perl Inline::Python module with a python class that was
>inheriting from the new builting 'object' class like so:
>
>class MyClass(object):
>
>The problem is in detecting that this class should be treated as a class
>from C.  With old-style classes, PyClass_Check() returns true, but it
>doesn't work with new-style classes.  With those, apparently we have to
>use PyType_Check(), but I cannot find this in the extension
>documentation.
>
>Another problem comes in identifying instances of this type of
>type-class, where PyInstance_Check() no longer returns true.
>
>Does anyone know of any documentation for the API for new-style classes?
>(It must work somehow or the python interpreter couldn't do it.)

I'm no expert on this, but since nobody else has stepped up to the
plate...

New-style classes make things both easier and harder.  Fundamentally,
there's no longer any difference between a type and an instance --
that's how you get metaclasses that generate classes as their instances.
Unfortunately, your best bet is to look at the source of the new builtin
objects to see how they work.

Let's turn this around a bit: what problem are you trying to solve?
-- 
Aahz (aahz at pythoncraft.com)           <*>         http://www.pythoncraft.com/

"as long as we like the same operating system, things are cool." --piranha



More information about the Python-list mailing list