Commits

Antonio Cuni committed d1d6190

allow break_on_setattr also on classes which define their own __setattr__

  • Participants
  • Parent commits 3fdc6d7

Comments (0)

Files changed (2)

             if attr == attrname and condition(self, value):
                 set_trace()
             old___setattr__(self, attr, value)
-        assert '__setattr__' not in cls.__dict__
         cls.__setattr__ = __setattr__
         return cls
     return decorator

File test/test_pdb.py

 -> a.bar = 42
 # c
 """)
+
+def test_break_on_setattr_overridden():
+    @pdb.break_on_setattr('x', set_trace=set_trace)
+    class Foo(object):
+        def __setattr__(self, attr, value):
+            object.__setattr__(self, attr, value+1)
+
+    def fn():
+        obj = Foo()
+        obj.y = 41
+        obj.x = 0
+        return obj.x
+
+    check(fn, """
+1 frames hidden
+> .*fn()
+-> obj.x = 0
+# obj.y
+42
+# hasattr(obj, 'x')
+False
+# n
+> .*fn()
+-> return obj.x
+# print obj.x
+1
+# c
+""")