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 ncoghlan
Recipients NeilGirdhar, docs@python, ncoghlan
Date 2016-10-16.07:37:12
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1476603432.33.0.261832836777.issue28437@psf.upfronthosting.co.za>
In-reply-to
Content
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.
History
Date User Action Args
2016-10-16 07:37:12ncoghlansetrecipients: + ncoghlan, docs@python, NeilGirdhar
2016-10-16 07:37:12ncoghlansetmessageid: <1476603432.33.0.261832836777.issue28437@psf.upfronthosting.co.za>
2016-10-16 07:37:12ncoghlanlinkissue28437 messages
2016-10-16 07:37:12ncoghlancreate