Created
September 3, 2009 22:14
-
-
Save kevinw/180568 to your computer and use it in GitHub Desktop.
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
from traceback import print_exc | |
class debug_property(object): | |
''' | |
Doesn't squash AttributeError. | |
''' | |
def __init__(self, fget=None, fset=None, fdel=None, doc=None): | |
self.__get = fget | |
self.__set = fset | |
self.__del = fdel | |
self.__doc__ = doc | |
def __get__(self, inst, type=None): | |
if inst is None: | |
return self | |
if self.__get is None: | |
raise AttributeError, "unreadable attribute" | |
try: | |
return self.__get(inst) | |
except AttributeError, e: | |
# don't allow attribute errors to be squashed | |
print_exc() | |
raise AssertionError('attribute error during __get__') | |
def __set__(self, inst, value): | |
if self.__set is None: | |
raise AttributeError, "can't set attribute" | |
try: | |
return self.__set(inst, value) | |
except AttributeError, e: | |
print_exc() | |
raise AssertionError('attribute error during __set__') | |
def __delete__(self, inst): | |
if self.__del is None: | |
raise AttributeError, "can't delete attribute" | |
try: | |
return self.__del(inst) | |
except AttributeError, e: | |
print_exc() | |
raise AssertionError('attribute error during __del__') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment