Skip to content

Instantly share code, notes, and snippets.

@exogen
Created March 23, 2010 23:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save exogen/341816 to your computer and use it in GitHub Desktop.
Save exogen/341816 to your computer and use it in GitHub Desktop.
import inspect
class Meta(type):
def __init__(cls, name, bases, attrs):
for attr, value in attrs.items():
if inspect.isfunction(value):
setattr(cls, attr, decorate(value))
for base in bases:
for attr in dir(base):
value = getattr(base, attr)
if inspect.ismethod(value):
setattr(cls, attr, decorate(value))
def decorate(func):
# Check the flag to prevent double decoration.
if getattr(func, '_decorated', False):
return func
def decorated(instance, *args, **kwargs):
return func(instance, *args, **kwargs)
# Set the flag to prevent double decoration.
decorated._decorated = True
return decorated
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment