cls = type("Test", (Base,), {"__metaclass__": Meta, "a": 1, ...})
I want to make some check for the attrs in the 3rd argument with Meta class, but this seem not worked, is there any other method?
cls = type("Test", (Base,), {"__metaclass__": Meta, "a": 1, ...})
I want to make some check for the attrs in the 3rd argument with Meta class, but this seem not worked, is there any other method?
Meta
-class is a subclass of type
. So creating a type of a metaclass is calling the meta class:
cls = Meta("Test", (Base,), {"a": 1, ...})
You should create your Test
class by calling the Meta
(a.k.a. type.__class__.__new__(Meta, "Test", (Base,), {"__metaclass__": Meta, "a": 1})
.
If you have a dictionary with possible __metaclass__
, you can use the following code:
members = {"__metaclass__": Meta, "a": 1, ...}
metaclass = members.pop('__metaclass__', type)
cls = metaclass("Test", (Base,), members)