[Python-Dev] metaclass insanity

Guido van Rossum guido@python.org
Mon, 04 Nov 2002 16:54:16 -0500

> > Can someone provide a reason why you'd want to use nested classes?
> > I've never felt this need myself.  What are the motivations?
> Nested classes provide a nice way (IMO) to write metaclasses and keep
> them near the classes using them:
> class X(object):
>     class __metaclass__(type):
>         ....

Sorry, that looks really ugly to me, and makes it impossible to share
a metaclass.  It sounds like you're trying to emulate Smalltalk's idea
of metaclasses.  Don't do this; Python's concept of metaclasses is
different, and trying to do it the Smalltalk way is
counterproductive.  (For example, multiple inheritance from two
classes with different metaclasses doesn't work unless one metaclass
inherits from the other.)

--Guido van Rossum (home page: http://www.python.org/~guido/)