On Wed, May 9, 2012 at 8:37 AM, Tres Seaver <tsea...@palladion.com> wrote: >> No, the "mcl" in the call is just the designated metaclass - the >> *actual* metaclass of the resulting class definition may be something >> different. That's why this is a separate method from mcl.__new__. > > Why not make it a static method, if there is no notion of a useful 'cls' > argument?
We need the explicitly declared metaclass as well as the bases in order to determine the correct metaclass. As a static method, the invocation would look like: type.build_class(mcl, bases, keywords, exec_body) Since mcl will always be an instance of type in 3.x (due to all classes being subtypes of object), it makes more sense to just make it a class method and invoke the method on the declared metaclass: mcl.build_class(bases, keywords, exec_body) The following assertion *does not* hold reliably: cls = mcl.build_class(bases, keywords, exec_body) assert type(cls) == mcl # Not guaranteed Instead, the invariant that holds is the weaker assertion: cls = mcl.build_class(bases, keywords, exec_body) assert isinstance(cls, mcl) This is due to the fact that one of the bases may specify that the actual metaclass is a subtype of mcl rather than mcl itself. Cheers, Nick. -- Nick Coghlan | ncogh...@gmail.com | Brisbane, Australia _______________________________________________ Python-Dev mailing list Python-Dev@python.org http://mail.python.org/mailman/listinfo/python-dev Unsubscribe: http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com