Created
June 5, 2012 20:10
-
-
Save phill-tornroth/2877507 to your computer and use it in GitHub Desktop.
Playing with class decorators
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
>>> class my_dec(object): | |
... def __init__(self, f): | |
... self.f = f | |
... | |
>>> class my_dec(object): | |
... def __init__(self, f): | |
... self.f = f | |
... def __call__(self, *args): | |
... return self.f(*args) | |
... | |
>>> @my_dec | |
... def my_func(x,y): | |
... return y-x | |
... | |
>>> isinstance(my_func, my_dec) | |
True | |
>>> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment