[Python-Dev] PyInstance_Check() and new-style classes
ewilhelm at sbcglobal.net
Mon Jul 12 16:15:07 CEST 2004
# The following was supposedly scribed by
# Phillip J. Eby
# on Monday 12 July 2004 08:48 am:
>If you want to find out whether a type was defined in Python or C, you can
>use the "heap type" flag in the type structure. Note, however, that this
>will not let you distinguish between core C types and C extension types, so
>using it might be a bad idea if the reason you're using Python is to use a
>Python module written in C!
I'm not sure if I understand what this flag is telling me. According to the
api/type-structs.html, Py_TPFLAGS_HEAPTYPE is set when the object is
allocated. To me, that reads that it would be set for builtin tuples, etc
even if they were not subclassed.
What about Py_TPFLAGS_HAVE_CLASS ?
>> Also, it
>>seems that it would fail if a class inherited from a built-in type. I'm
>>almost sure that I'm way off-course, so if anyone could put me on track,
>> I'd really appreciate it.
>Why do you want to distinguish between different kinds of objects? Is it
>because Perl needs/wants Python strings and numbers to become
To have a useful binding, yes.
We want to create constructors for constructors, methods for methods, and
translate everything else into native scalars, hashes, and lists.
>Perhaps you should simply convert those types that you want an
>exact conversion for, and consider everything else to be
That has been the current approach. The trouble is, we need to know that they
are instances so we can bless them, and we need to know that they are
instances of a user-defined class, even if they are subtypes of builtin
More information about the Python-Dev