Diez B. Roggisch wrote: >>> >>> I think '__metaclass__ = whatever' affects only the creation of >>> classes that >>> would otherwise be old-style classes? >> >> Wrong. >> >> If you set __metaclass__ = type, every class in that module will be >> new-style. >> >> If you set __metaclass__ = MyClass, and MyClass inherits from <type>, every >> class in that module will be new-style and have MyClass as a metaclass. >> >> The usual way to create new-style classes, inheriting from object or >> another >> new-style class, works because if no __metaclass__ is defined, the first >> base class's class is taken as the metaclass. > > > I was under that impression, too. But this behaves different (py2.4):
[...] > deets$ python2.4 /tmp/test.py > (<class '__main__.meta'>, 'OldStyle', (), {'__module__': '__main__'}) > deets$ > > I was astonished to see that. Any explanation? Yes. I was wrong, the order of lookup is reversed. This first base class's class is used before the global __metaclass__. So what Damjan said is correct: global __metaclass__ is only usable for classes that don't have bases. Whether this is desirable is another question... Georg -- http://mail.python.org/mailman/listinfo/python-list