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 NeilGirdhar
Recipients NeilGirdhar, docs@python
Date 2016-10-13.23:50:59
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1476402659.83.0.311331660228.issue28437@psf.upfronthosting.co.za>
In-reply-to
Content
Minimum working example:

class MyMetaclass(type):
    pass

class OtherMetaclass(type):
    pass

def metaclass_callable(name, bases, namespace):
    return OtherMetaclass(name, bases, namespace)

class MyClass(metaclass=MyMetaclass):
    pass

try:
    class MyDerived(MyClass, metaclass=metaclass_callable):
        pass
except:
    print("Gotcha!")


from types import new_class
MyDerived = new_class("MyDerived", (), dict(metaclass=metaclass_callable))

print(type(MyDerived))


This is because something happened along the way and Objects/typeobject.c:type_new no longer coincides with Lib/types.py:new_class. The Python version conditionally calls _calculate_meta whereas the C version calls it unconditionally. I consider the C implementation to be the "correct" version.

I suggest that
* the Python version be made to coincide with the C version.
* the documentation be made to coincide with the C version.  Specifically, section 3.3.3.2 should read:


"The metaclass of a class definition is selected from the explicitly specified metaclass (if any) and the metaclasses (i.e. type(cls)) of all specified base classes. The selected metaclass is the one which is a subtype of all of these candidate metaclasses. If none of the candidate metaclasses meets that criterion, then the class definition will fail with TypeError. If provided, the explicit metaclass must be a callable accepting the positional arguments (name, bases, _dict) as in the three argument form of the built-in type function."
History
Date User Action Args
2016-10-13 23:50:59NeilGirdharsetrecipients: + NeilGirdhar, docs@python
2016-10-13 23:50:59NeilGirdharsetmessageid: <1476402659.83.0.311331660228.issue28437@psf.upfronthosting.co.za>
2016-10-13 23:50:59NeilGirdharlinkissue28437 messages
2016-10-13 23:50:59NeilGirdharcreate