Variable 'superclass'es?

Tim Peters tim_one at email.msn.com
Fri May 7 00:48:55 EDT 1999


[Neel Krishnaswami, with much good advice]
> ...
> The __bases__ special attribute of a class object displays the
> superclasses of that class. We can't assign to it, though, so
> you can't change a class's superclasses that way. (Though you
> can change an instance's class by assigning to its __class__
> method.)

As of the 1.5.2 release, you can assign to the __bases__ attribute.  I used
to be appalled by suggestions like this, except that:

> ...
> A third possibility (and you thought that only Perl had more than one
> way to do it) is to create a metaclass that creates the child classes
> as instances of itself.

There are only two people in the world who can write a robust Python
metaclass, and they're both certifiably insane.  The only sane people who
should even think about considering metaclasses are those who intend to use
what Jim Fulton prepackaged for them via his ExtensionClasses package.

Python2 may have a less head-exploding approach to metaclass functionality,
but you'd do yourself a true favor by pretending metaclasses don't exist in
Python1.

let-them-grab-you-by-the-throat-once-and-they-merge-with-the-
    short-hairs-forever-ly y'rs  - tim






More information about the Python-list mailing list