PEP 235: role of PyType_GenericNew()

Ralf Juengling juenglin at informatik.uni-freiburg.de
Thu Apr 4 03:39:52 EST 2002


Gustavo Niemeyer <niemeyer at conectiva.com> writes:

> Hi Ralf!
> 
> > I'm wondering whether the current implementation of PyType_GenericNew
> > does, what it's supposed to do.
> [...]
> > Thus, only the allocator of the passed type is called.
> > Shouldn't the base classes allocators be called as well?
> 
> If you're inheriting from another object, and you don't want to
> do anything special at object initialization time, why would you
> use this function in the first place? Just leave the slot empty
> and allow the super class to initialize itself. If you implement
> your special function, it's your business to call the super class.
> 

That's the point, why I consider PyType_GenericNew's current behaviour
a bug!

What I want to do:

Write a base-class _A in C, which fills the type's tp_alloc-slot with
its special allocator, for the tp_new slot I simply use PyType_GenericNew.
At the Python level I write a class A which is a subclass of _A. Since
A does not introduce new data members, there is no need to overwrite
__new__. This way, however, the superclass-allocator (_A.alloc) never
gets called when I create instances of A...

Regards,
Ralf

 




More information about the Python-list mailing list