This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author daniel.urban
Recipients daniel.urban, georg.brandl, pwerneck, rodsenra, terry.reedy
Date 2010-08-08.07:56:34
SpamBayes Score 5.1115e-06
Marked as misclassified No
Message-id <1281254197.7.0.909842121134.issue1294232@psf.upfronthosting.co.za>
In-reply-to
Content
I think the situation is a bit more complicated. Here is the example described by Pedro Werneck (this is py3k, but its essentially the same in 2.x):

>>> class M_A(type):
...     def __new__(mcls, name, bases, ns):
...             print('M_A.__new__')
...             return super().__new__(mcls, name, bases, ns)
...
>>> class A(metaclass=M_A): pass
...
M_A.__new__
>>>
>>>
>>> class M_B(M_A):
...     def __new__(mcls, name, bases, ns):
...             print('M_B.__new__')
...             return super().__new__(mcls, name, bases, ns)
...
>>> class B(A, metaclass=M_B): pass
...
M_B.__new__
M_A.__new__
>>>
>>>
>>> class C(B, metaclass=M_A): pass
...
M_A.__new__
M_B.__new__
M_A.__new__
>>> 

As it is clear from the last three lines, the given metaclass (M_A) to C is not ignored. It is actually called (and produces the 'M_A.__new__' output line). Then M_A.__new__ calls type.__new__ (with super()). type.__new__ then searches the bases of C, find the metaclass of B, M_B, and calls its __new__. M_B.__new__ then prints the line 'M_B.__new__', then calls M_A.__new__ again (with super()). This produces the last line, 'M_A.__new__'. So the trick is in type.__new__.
History
Date User Action Args
2010-08-08 07:56:38daniel.urbansetrecipients: + daniel.urban, georg.brandl, terry.reedy, rodsenra, pwerneck
2010-08-08 07:56:37daniel.urbansetmessageid: <1281254197.7.0.909842121134.issue1294232@psf.upfronthosting.co.za>
2010-08-08 07:56:35daniel.urbanlinkissue1294232 messages
2010-08-08 07:56:34daniel.urbancreate