I try define class decorator. I have problem with __init__
method in decorated class. If __init__
method invokes super
the RuntimeError
maximum recursion depth exceeded is raised.
Code example:
def decorate(cls):
class NewClass(cls): pass
return NewClass
@decorate
class Foo(object):
def __init__(self, *args, **kwargs):
super(Foo, self).__init__(*args, **kwargs)
What am I doing wrong?
Thanks, Michał
Edit 1
Thanks to Mike Boers answer I realized that correct question is what should I do to achive that super(Foo, self) point to proper class.
I have also two limitation. I want invoke Foo.__init__
method and I can't change Foo
class definition.
Edit 2
I have solved this problem. I modify decorator function body. I don't return new class. Instead of I wrap methods of orginal class.