I'm writing a metaclass, and I want an additional method to be called between __new__ and __init__.
If I were calling the method before __new__ or after __init__ I could write e.g.
class Meta(type):
def __call__(cls):
ret = type.__call__()
ret.extraMethod()
My temptation is to write
class Meta(type):
def __call__(cls):
ret = cls.__new__(cls)
ret.extraMethod()
ret.__init__()
return ret
and just reproduce the functionality of type.__call__ myself. But I'm afraid there might be some subtlety to type.__call__ I have omitted, which will lead to unexpected behavior when my metaclass is implemented.
I cannot call extraMethod from __init__ or __new__ because I want users of my metaclass to be able to override __init__ and __new__ as in normal Python classes, but to still execute important set-up code in extraMethod.
Thanks!