[issue36593] Trace function interferes with MagicMock isinstance?

Karthikeyan Singaravelan report at bugs.python.org
Wed Apr 10 20:30:28 EDT 2019


Karthikeyan Singaravelan <tir.karthi at gmail.com> added the comment:

On an initial guess this is the change that went through and using object.__delattr__(self, name) instead of super().__delattr__(name) restores the old behavior and there are no test case failures. But I still have to check the change and how it's related to set trace.


diff --git a/Lib/unittest/mock.py b/Lib/unittest/mock.py
index 955af5d2b8..42fbc22e74 100644
--- a/Lib/unittest/mock.py
+++ b/Lib/unittest/mock.py
@@ -728,11 +728,10 @@ class NonCallableMock(Base):
                 # not set on the instance itself
                 return

-        if name in self.__dict__:
-            object.__delattr__(self, name)
-
         obj = self._mock_children.get(name, _missing)
-        if obj is _deleted:
+        if name in self.__dict__:
+            super().__delattr__(name)
+        elif obj is _deleted:
             raise AttributeError(name)
         if obj is not _missing:
             del self._mock_children[name]

----------

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue36593>
_______________________________________


More information about the Python-bugs-list mailing list