[Python-Dev] Making types behave like classes

Thomas Heller thomas.heller@ion-tof.com
Mon, 2 Apr 2001 19:02:11 +0200


> These are some half-baked ideas about getting classes and types to look
> more similar.

Somewhat different thoughts:

Which limitations are there in python as a consequence
of the type/class split?

In python code itself, it is not too bad. Instead of deriving
from builtin types, you can always delegate to them.

In c-code, the situation is worse, on the other hand,
ExtensionClass comes to rescue. Write the base class in C,
subclass in python.

The worst limitation is in the most useful builtin object:
the dictionary. One can use or derive from UserDict,
but one cannot pass UserDict instances or other homegrown dict
lookalikes to exec, you cannot use them as class or instance
dictionaries.

If this limitation would be removed, you could implement your
own rules in namespaces: readonly, case insentitive, whatever.
One could even implement a mapping object in a C extension,
and use it in the aforementioned ways.

IMO this limitation would be easy to remove:
The current PyDict_* API could be implemented in terms of
the PyMapping_ and PyObject_ protocol, using different code
depending on the outcome of an additional PyDict_Check() test.

The performance hit would be rather small.

Thomas