Skip to content

Instantly share code, notes, and snippets.

@jparise
Created March 30, 2011 01:18
Show Gist options
  • Save jparise/893690 to your computer and use it in GitHub Desktop.
Save jparise/893690 to your computer and use it in GitHub Desktop.
Class attributes can only be accessed via class type objects
class ClassAttribute(object):
"""Class attributes can only be accessed via class type objects.
Attempting to access the attribute via an instance of the class will
result in an AttributeError.
"""
__slots__ = ('attr',)
def __init__(self, attr):
self.attr = attr
def __get__(self, instance, type=None):
if instance is not None:
raise AttributeError("Attribute is not accessible via %s instances"
% type.__name__)
return self.attr
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment