0

In Call overridden base class method without triggering the base class decorator I am able to skip a decoration, but in reality I have class methods that looks like

class MyClass:
  @patch(foo)
  @setup_test(bar)
  def test_something()
    do stuff

In order to call the original function, I need to call super().test_something.__wrapped__.__wrapped__(self) which is ugly. I could write something like

def orig(f):
    while hasattr(f, '__wrapped__'):
        f = f.__wrapped__
    return f

orig(super().test_something)(self)

What is a better way than this?

wonton
  • 7,568
  • 9
  • 56
  • 93
  • No, you are not _"skipping decoration"_. Decoration still happens as soon as `MyClass` is built. You are just accessing the `__wrapped__` attribute of the object returned by the decorator. And this only works because the decorator adds that attribute. If it didn't, there would be **no reference left** to the original function. So no, there is no better way. – Daniil Fajnberg Feb 07 '23 at 09:15

0 Answers0