Extension Classes, Python Extension Types Become Classes

Jim Fulton, Digital Creations, Inc. jim@digicool.com

Copyright (C) 1996-1998, Digital Creations.

Abstract

A lightweight mechanism has been developed for making Python extension types more class-like. Classes can be developed in an extension language, such as C or C++, and these classes can be treated like other python classes:

An example class shows how extension classes are implemented and how they differ from extension types.

Extension classes provide additional extensions to class and instance semantics, including:

Extension classes illustrate how the Python class mechanism can be extended and may provide a basis for improved or specialized class models.

Releases

To find out what's changed in this release, see the release notes.

Problem

Currently, Python provides two ways of defining new kinds of objects:

Each approach has it's strengths. Extension types provide much greater control to the programmer and, generally, better performance. Because extension types are written in C, the programmer has greater access to external resources. (Note that Python's use of the term type has little to do with the notion of type as a formal specification.)

Classes provide a higher level of abstraction and are generally much easier to develop. Classes provide full inheritance support, while support for inheritance when developing extension types is very limited. Classes provide run-time meta-data, such as method documentation strings, that are useful for documentation and discovery. Classes act as factories for creating instances, while separate functions must be provided to create instances of types.

It would be useful to combine the features of the two approaches. It would be useful to be able to have better support for inheritance for types, or to be able to subclass from types in Python. It would be useful to be able to