Recursion error in metaclass
Steven D'Aprano
steve+comp.lang.python at pearwood.info
Sat Jun 11 07:38:28 EDT 2011
On Sat, 11 Jun 2011 01:33:25 -0400, Terry Reedy wrote:
> On 6/10/2011 11:34 PM, Steven D'Aprano wrote:
>> I have a metaclass in Python 3.1:
>>
>> class MC1(type):
>> @staticmethod
>> def get_mro(bases):
>> print('get_mro called')
>> return type('K', bases, {}).__mro__[1:]
>
> The call to type figures out the proper metaclass from bases and
> forwards the call to that (or to its __new__ method).
[...]
> Since uou do not pass dict to get_mro. it passes {} to type and MC1 and
> the test for docstring fails and the loop is broken and the empty class
> is discarded after getting its mro.
Thanks for the explanation. You confused me for a while talking about
MC1, because that's the metaclass that *doesn't* raise an exception, but
I think I see the issue now.
--
Steven
More information about the Python-list
mailing list