- publishing free software manuals
Python Language Reference Manual
by Guido van Rossum and Fred L. Drake, Jr.
Paperback (6"x9"), 120 pages
ISBN 0954161785
RRP £12.95 ($19.95)

Sales of this book support the Python Software Foundation! Get a printed copy>>>

3.4.3 Customizing class creation

By default, new-style classes are constructed using type(). A class definition is read into a separate namespace and the value of the class name is bound to the result of type(name, bases, dict).

When the class definition is read, if __metaclass__ is defined then the callable assigned to it will be called instead of type(). This allows classes or functions to be written which monitor or alter the class creation process:

This variable can be any callable accepting arguments for name, bases, and dict. Upon class creation, the callable is used instead of the built-in type(). (Added in Python version 2.2)

The appropriate metaclass is determined by the following precedence rules:

The potential uses for metaclasses are boundless. Some ideas that have been explored including logging, interface checking, automatic delegation, automatic property creation, proxies, frameworks, and automatic resource locking/synchronization.

ISBN 0954161785Python Language Reference ManualSee the print edition