0

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.

Risadinha
  • 16,058
  • 2
  • 88
  • 91
user204936
  • 11
  • 1
  • I think you can't add attribute to a `bound method` object - http://stackoverflow.com/a/8847168/5922757 – Jezor Jul 09 '16 at 19:37
  • Are you saying that what I did in class A is not ok? It looks ok to me... the reference did not help me. Do you have a more specific one?Thanks any way, you are probably wright, I am not very experienced. – user204936 Jul 09 '16 at 20:47

0 Answers0