PEP 235: role of PyType_GenericNew()

Gustavo Niemeyer niemeyer at conectiva.com
Thu Apr 4 11:49:11 EST 2002


> 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.

Ok..

> At the Python level I write a class A which is a subclass of _A. Since

No problems..

> 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...

And that's ok as well. You can't allocate memory area for the same
object instance two times. Indeed, I'm not sure why you're mentioning
that __new__ was not overwritten in python level. The allocator function
called will be the same, no matter if it's overwritten or not (you can't
allocate memory at the python level). Also, introducing data members is
not a reason for overwriting __new__. Ralf, you seem to be confused
about the uses of tp_init (__init__), tp_new (__new__), and tp_alloc
slots. Have you read PEP 253?

-- 
Gustavo Niemeyer

[ 2AAC 7928 0FBF 0299 5EB5  60E2 2253 B29A 6664 3A0C ]





More information about the Python-list mailing list