Py_TPFLAGS_HEAPTYPE, what's its real meaning ?

Boris Boutillier boris.boutillier at arteris.net
Thu Oct 30 03:39:43 EST 2003


Hi all,

I've got problems with the Py_TPFLAGS_HEAPTYPE and the new 
'hackcheck' in python 2.3.

I'm writing a C-extension module for python 2.3.
I need to declare a new class, MyClass.
For this class I want two things :
1) redefine the setattr function on objects of this class
  (ie setting a new tp_setattro)
2) I want that the python user can change attributes on MyClass (the
class itself).

Now I have a conflict on the Py_TPFLAGS_HEAPTYPE with new Python 2.3.
If I have Py_TPFLAGS_HEAPTYPE set on MyClass, I'll have problem with the
new hackcheck (Object/typeobject.c:3631), as I am a HEAPTYPE but I also
redefine tp_setattro.
If I don't have Py_TPFLAGS_HEAPTYPE, the user can't set new attributes on
my class because of a check in type_setattro (Object/typeobject.c:2047).

The only solution I've got without modifying python source is to create 
a specific Metaclass for Myclass, and write the tp_setattr.
But I don't like the idea of making a copy-paste of the type_setattr 
source code, just to remove a check, this is not great for future 
compatibility with python (at each revision of Python I have to check if 
type_setattr has not change to copy-paste the changes).
In fact I'm really wondering what's the real meaning of this flags, but 
I think there is some history behind it.


Boris




More information about the Python-list mailing list