1 | initial version |
The method to invoke the base function within a metaclass is to call the base class's method using the super()
function. For example:
class MyMeta(type):
def __new__(mcls, name, bases, attrs):
# Call the base class's __new__() method
obj = super().__new__(mcls, name, bases, attrs)
# Add your custom logic here
return obj
In this example, super().__new__(mcls, name, bases, attrs)
calls the __new__()
method of the parent type
class, which returns a new instance of the class. You can then add your custom logic to the new class object before returning it.