Skip to content

Instantly share code, notes, and snippets.

@alanbriolat
Created June 6, 2012 11:39
Show Gist options
  • Save alanbriolat/2881415 to your computer and use it in GitHub Desktop.
Save alanbriolat/2881415 to your computer and use it in GitHub Desktop.
Descriptor not seen as class in Sphinx
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