Message278744
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? |
|
Date |
User |
Action |
Args |
2016-10-16 07:22:48 | NeilGirdhar | set | recipients:
+ NeilGirdhar, ncoghlan, docs@python |
2016-10-16 07:22:48 | NeilGirdhar | set | messageid: <1476602568.15.0.740217518653.issue28437@psf.upfronthosting.co.za> |
2016-10-16 07:22:48 | NeilGirdhar | link | issue28437 messages |
2016-10-16 07:22:47 | NeilGirdhar | create | |
|