-
-
Save AeroNotix/3eaf72534a70a4c73dba to your computer and use it in GitHub Desktop.
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
def random_device(reuse_owner=False, **kwds): | |
def wrapper(f): | |
def wrapped(self): | |
if reuse_owner and hasattr(self, 'device'): | |
print "Reusing owner %s" % self.device | |
else: | |
print "no owner" | |
return f(self) | |
return wrapped | |
return wrapper | |
class Foo(object): | |
def __init__(self): | |
self.x = 10 | |
self.device = "lol" | |
@random_device(reuse_owner=True) | |
def something(self, **kwargs): | |
print kwargs | |
print self.x | |
print self.device | |
Foo().something() | |
# Reusing owner lol | |
# {} | |
# 10 | |
# lol |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment