Skip to content

Instantly share code, notes, and snippets.

@allenyang79
Last active October 24, 2019 06:09
Show Gist options
  • Save allenyang79/794a6703348063e7d83e0ed9c3136f30 to your computer and use it in GitHub Desktop.
Save allenyang79/794a6703348063e7d83e0ed9c3136f30 to your computer and use it in GitHub Desktop.
wrapt
import wrapt
@wrapt.decorator
def pass_through(wrapped, instance, args, kwargs):
print("pass_through", wrapped, instance, args, kwargs)
return wrapped(*args, **kwargs)
@pass_through
def foo():
print("foo")
print("========")
foo()
========
pass_through <function foo at 0x104908e60> None () {}
foo
@wrapt.decorator
def pass_through(wrapped, instance, args, kwargs):
print("pass_through", instance, args, kwargs)
return wrapped(*args, **kwargs)
@pass_through
class Foo:
def __init__(self, name):
self.name = name
@pass_through
def hi(self):
print(f"hi, {self.name}")
print("======")
f = Foo("foo")
f.hi()
======
pass_through None ('foo',) {}
pass_through <__main__.Foo object at 0x10051e310> () {}
hi, foo
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment