Created
March 30, 2011 01:18
-
-
Save jparise/893690 to your computer and use it in GitHub Desktop.
Class attributes can only be accessed via class type objects
This file contains 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
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