0

How to use a class variable as class methods's decorator parameter?

class Test:
  def __init__(self, value):
    self.value = value

  @decorator(self.value) # <-- problem here ;)
  def method():
    pass

Of course self.value is out of scope to be used as decorator parameter. How could I refactor this to allow it?

Thanks!

andreas
  • 1,483
  • 1
  • 15
  • 36
  • Can you describe the purpose of your decorator? Or better - post it if possible – RomanPerekhrest Oct 15 '19 at 10:37
  • @RomanPerekhrest: In the real code there are actually two decorators. One (the inner) is a generic rate limiter, which is utilizing a module to use redis for synchronization between processes/instances. The second (outer decorator) is catching the RateLimitException of the inner, sleeps a random bit and retries again. The functionality is completly unrelated to the class method functionality and I dont't want to mix it up. – andreas Oct 15 '19 at 11:12
  • Possible duplicate of question [Python class method decorator with self arguments?](https://stackoverflow.com/questions/11731136/python-class-method-decorator-with-self-arguments) – Gerd Oct 29 '19 at 09:22

0 Answers0