Skip to content

Instantly share code, notes, and snippets.

@iivvoo
Created December 29, 2016 13:11
Show Gist options
  • Save iivvoo/9d0aca3898f32b7108ce12084f055dd5 to your computer and use it in GitHub Desktop.
Save iivvoo/9d0aca3898f32b7108ce12084f055dd5 to your computer and use it in GitHub Desktop.
def classproperty(f):
"""
E.g.
>>> class foo(object):
... @classproperty
... def name(cls):
... return cls.__name__
>>> print foo.name
'foo'
"""
class name(object):
def __init__(self, getter):
self.getter = getter
def __get__(self, obj, type=None):
return self.getter(type)
return name(f)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment