Created
June 6, 2012 11:39
-
-
Save alanbriolat/2881415 to your computer and use it in GitHub Desktop.
Descriptor not seen as class in Sphinx
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 ValueFilter(object): | |
"""A descriptor which applies *filter* to assigned values, which are stored | |
at *attr*. If the value is unset it is *default*. | |
""" | |
def __init__(self, attr, filter, default=None): | |
self.attr = attr | |
self.filter = filter | |
self.default = default | |
def __get__(self, instance, owner): | |
if instance is None: | |
return getattr(owner, self.attr, self.default) | |
else: | |
return getattr(instance, self.attr, self.default) | |
def __set__(self, instance, value): | |
setattr(instance, self.attr, self.filter(value)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment