Documentation on creating new types with slots in C ?

Alex Martelli aleax at
Fri Oct 17 18:03:32 CEST 2003

Thomas Heller wrote:
>>> Of what I heard Python 2.3 now allow creation of new types in C with
>>> slots.
> I would guess he means this:

i.e. METAtypes (types whose instances are types) with '__slots__' ...?

> and I would also be interested in an example.

Sorry, I've never written a metatype in C -- always in Python, almost
invariably inheriting from the built-in type.

"Normal" C types don't _need_ __slots__ of course, since __slots__'s
effect (avoiding a per-instance dict) is most easily achieved by
simply leaving the tp_dictoffset field at 0 (as most built-in types
do, save for those who DO want a per-instance dict -- functions and
modules come to mind).


More information about the Python-list mailing list