[issue28437] Documentation for handling of non-type metaclass hints is unclear

Nick Coghlan report at bugs.python.org
Sun Oct 16 03:37:12 EDT 2016


Nick Coghlan added the comment:

Because they're checking for different things:

- types.prepare_class is only checking "How do I call __prepare__?". It only triggers type resolution at that point if the metaclass hint is an instance of type, otherwise it skips that process entirely and queries the metaclass hint directly.

- type.__new__ is checking "Can I actually create a new instance of this metaclass with these bases?". It can only do that if either the metaclass being instantiated is a subclass of all the bases of the type being defined, or else such a metaclass exists amongst the bases.

To be clear, your example isn't failing due to the way MyDerived is defined - it's failing because OtherMetaclass is itself an instance of type, and you're declaring it (directly or indirectly) as the metaclass of MyDerived, while inheriting from MyClass, which is an instance of MyMetaclass.

----------

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue28437>
_______________________________________


More information about the Python-bugs-list mailing list