[Next] [Previous] [Up] [Top]

2. Object System Enhancements

2.1. Type Converters

The notion of a type converter plays a central role in building the system described below. The lack of type converters in the current Python implementation shows itself in many places. The struct module and the getargs() function are two very obvious examples. In order to extend the functionality in either of these areas requires making changes to the source code for the base implementation of Python. An appropriately designed type conversion system will eliminate this restriction and enhance the users ability to extend Python without changing the base implementation.

Almost any C data type can be described simply by four different operations:

In order to encapsulate these ideas, a new type object was derived from the type object that exists in the current Python implementation. This new type object, the CType object, is used to implement these four operations for any given C data type. Thus, CType objects facilitate the conversion of C data types to Python objects as well as the conversion from Python objects to C data types.

All CType objects are registered by name in a dictionary of type converters. A public interface to this dictionary is provided for adding new type converters and for looking up existing ones. It is this feature that allows new types to be added to the system without the necessity of changing source code of the base implementation.


Deriving Built-In Classes in Python - 22 DEC 94
[Next] [Previous] [Up] [Top]

Generated with CERN WebMaker