Chapter 7. Shadow Classes

Table of Contents
The PYTHON_OBJECT shadow classes
Example: Using Python primitives from within Eiffel
Unit tests
Simplifying the Python/C API in an Eiffel-compatible manner

As noted in "The Python/C API", SWIG can provide an acceptable interface to the voluminous and powerful Python/C API--unfortunately, in a rather unappealing, procedurally-oriented manner. For manipulating Python objects from within Eiffel, a better solution is desired. By creating a hierarchy of "shadow classes" in Eiffel, referencing the Python objects through an opaque pointer, manipulating Python objects can be as easy as native Eiffel objects.


After using SWIG to expose the Python/C API, we had a number of low-level options available to us--but no way to use them really cleanly from within Eiffel. While accessing and modifying Python objects of all types was now possible, it wasn't pretty at all. The solution lay in more indirection--wrapping the PYTHON_CLIENT class even more, forming a hierarchy of classes which mirror the divisions in the Python/C API