I am trying to pass some attributes from a method in a parent class to a method in a child class. And after that I wish to use a decorator that uses that attribute.
Suppose I have two classes and a decorator like these:
def my_decorator(fun):
inner(*args, **kwargs):
if fun.some_attr == 'value':
out = fun(*args, **kwargs)
else:
out = None
return out
return inner
class A:
def some_method_in_A(self):
return 1
some_method_in_A.some_attr = 'value'
class B(A):
@my_decorator
def some_method_in_B(self):
super(B, self).some_method_in_A()
What I want is to have some_attr set to 'value'
in some_method_in_B. This attribute has to be available for my_decorator
.
Is it possible to do it?
This is something that I would have to do for lots of methods in class B so it would be nice to do it in a compact way.