[Python-Dev] Re: Class/type dichotomy thoughts

M.-A. Lemburg mal@lemburg.com
Mon, 06 Nov 2000 21:01:40 +0100

Neil Schemenauer wrote:
> On Mon, Nov 06, 2000 at 06:02:51PM +0100, M.-A. Lemburg wrote:
> > Neil Schemenauer wrote:
> > > Behavior should be based solely on the type structure.  Extension
> > > types would then be able to behave exactly like any other builtin
> > > type.  Your coercion proposal and David's rich comparisions both
> > > remove some of this special casing based on type.
> >
> > Even though this could remove some of the problems, it doesn't
> > help much with a common use of Py<Type>_Check(): that of
> > using fast access macros and native Py<Type>_*() APIs once an
> > object has been classified as being of a certain type.
> > This usually improves performance.
> Can you clarify what you mean by "it doesn't help much"?  Do you
> mean that extension types will not be able to perform as well as
> types that get special treatment by the interpreter?  I think the
> major problem that extension types _cannot_ behave the same as
> the builtin types.

If you only define types by interface, the interpreter will have
to apply the interface availability checks every time it calls
a slot. This would cause a major performance hit which would not
be acceptable.

The "doesn't help much" refers to the fact that once an object
has been identified as say Integer you are free to use whatever
access macro or function you choose.

> > By changing the simple address compare to a type handle
> > system, we might be able to add some more flexibility to
> > the system while keeping b/w compatibility.
> I don't see what this buys us.  The Python interpreter shouldn't
> care about which type object it is dealing with.  Can you give an
> example of where you think this would be useful?

Take e.g. dictionaries: you could easily add a new dictionary
type which uses case-insensitive string keys by extending the
existing dictionary type.

The new type would reuse most of the slots of the original
type and only replace the ones needed for lookup with the
new logic for case-insensitivity.

Then it sets the type id to PyDict_TypeID and Python will
use it as if it were an original dictionary object. The
underlying type objects would be different though (and also
the type object address which is currently used to identify
a builtin type).

Marc-Andre Lemburg
Business:                                      http://www.lemburg.com/
Python Pages:                           http://www.lemburg.com/python/