3.4 The psyco.classes module

The psyco.classes module defines a practical metaclass that you can use in your applications. [Metaclasses were introduced in Python 2.2 only; this module contains no-op placeholders if you import it under Python 2.1.]

A metaclass is the type of a class. Just like a class controls how its instances behave, a metaclass controls how its classes behave. The purpose of the present metaclass is to make your classes more Psyco-friendly.

class psymetaclass
The new metaclass. This is a subclass of type. Any user-defined class using this metaclass will be a new-style class and will automatically bind all the methods defined in the class body for compilation with Psyco.

class __metaclass__
A synonym for psymetaclass.

class psyobj
An empty class whose metaclass is psymetaclass, suitable for subclassing in the same way that the built-in object is the generic empty new-style class which you can subclass.

See http://www.python.org/2.2.2/descrintro.html for more information about old-style vs. new-style classes. Be aware of the changes in semantics, as recalled in section 2.2 (Psyco tutorial).

By using psyco.classes.psymetaclass as the metaclass of your commonly-used classes, you make all your classes new-style (Psyco can produce faster code to handle instances of these classes than old-style instances). Additionally, Psyco will call psyco.bind for you on all methods defined in the class (this does not include inherited parent methods or methods added after the class is first created).


Subsections