Skip to content

Instantly share code, notes, and snippets.

@AeroNotix
Created May 14, 2014 19:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save AeroNotix/3eaf72534a70a4c73dba to your computer and use it in GitHub Desktop.
Save AeroNotix/3eaf72534a70a4c73dba to your computer and use it in GitHub Desktop.
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