Neil Girdhar added the comment:

Thanks for taking the time to explain, but it's still not working for me:

from types import new_class


class MyMetaclass(type):
    pass

class OtherMetaclass(type):
    pass

def metaclass_callable(name, bases, namespace):
    return new_class(name, bases, dict(metaclass=OtherMetaclass))

class MyClass(metaclass=MyMetaclass):
    pass

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


try:
    MyDerived = new_class("MyDerived", (MyClass,), 
dict(metaclass=metaclass_callable))
except:
    print("Gotcha again!")

So my questions are:

1. Why shouldn't Lib/types:new_class behave in exactly the same way as 
declaring a class using "class…" notation?

2. What's the point of checking if the metaclass is an instance of type?  It 
seems to me that in Python 2, non-type metaclasses did not have to be the "most 
derived class" (that's what the documentation seems to suggest with the second 
rule).  However, we no longer accept that in CPython 3 — neither in the 
Lib/types, nor in a regular declaration.  In fact, the exception is:

                        "metaclass conflict: "
                        "the metaclass of a derived class "
                        "must be a (non-strict) subclass "
                        "of the metaclasses of all its bases");

So why not just check that unconditionally in Lib/types.py?

----------

_______________________________________
Python tracker <rep...@bugs.python.org>
<http://bugs.python.org/issue28437>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to