Created
October 16, 2013 12:51
-
-
Save pkit/7007174 to your computer and use it in GitHub Desktop.
How to debug access to properties in foreign classes...
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
def _debug_property(): | |
def getter(self): | |
traceback.print_stack() | |
return self._property | |
def setter(self, value): | |
traceback.print_stack() | |
print "value = %d" % value | |
self._property = value | |
return property(getter, setter) | |
def _add_debug_prop(inst, name): | |
cls = type(inst) | |
if not hasattr(cls, '__debug_property'): | |
cls = type(cls.__name__, (cls,), {}) | |
cls.__debug_property = True | |
inst.__class__ = cls | |
setattr(cls, name, _debug_property()) | |
import module | |
my_inst = module.SomeClass() | |
_add_debug_prop(my_inst, 'property_name') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment