Created
May 4, 2017 21:28
-
-
Save hanxiao/a5c08238a5600b48f1e0f08ae68cab83 to your computer and use it in GitHub Desktop.
python in class decorator with parameter
This file contains 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
class Baaar: | |
def __init__(self): | |
self.z = 10 | |
def wrapper(v:int = 0): | |
def f2(f): | |
def f2_v(self, *args, **kwargs): | |
print('z=%d' % self.z) | |
return f(self, *args, **kwargs) + v | |
return f2_v | |
return f2 | |
@wrapper(4) | |
def foo(self, x:int): | |
return 3+x | |
@wrapper(4) | |
def foo1(self, x:int): | |
return 3+x+self.z | |
@wrapper(4) | |
def foo2(self, x:int, y: int): | |
return 3+x*y + self.z | |
a = Baaar() | |
print(a.foo(1)) | |
print(a.foo1(1)) | |
print(a.foo2(1,6)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment