Hello I am recently looking about the metaclass in Python.
I learned about we can attach a metaclass to a class in this way:
class Metaclass(type):
...
class MyClass(metaclass=Metaclass):
...
- The first question
I wonder what's the principle of the keyword argument (metaclass=...) in the above example. There seems no description for that in the doc
I know that there is keyword argument for a function, but I've never seen the form occurred in class inheritance.
- The second question
We know that we can create a class using type() function in this way
cls = type(class_name, (base_class,), {func_name: func_ref})
Considering the metaclass=... form, how can I pass metaclass when creating class using type() instead of class keyword?
Thanks stackoverflowers!
metaclasskwarg is mentioned in the docstype(_, _, _)does not seem to be possibletype.type(_, _, _)gets replaced withMetaclass(_, _, _).