Last active
October 24, 2019 06:09
-
-
Save allenyang79/794a6703348063e7d83e0ed9c3136f30 to your computer and use it in GitHub Desktop.
wrapt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
======== | |
pass_through <function foo at 0x104908e60> None () {} | |
foo |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@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() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
====== | |
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