This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author michael.foord
Recipients michael.foord
Date 2014-01-13.11:15:01
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1389611701.97.0.048361560176.issue20239@psf.upfronthosting.co.za>
In-reply-to
Content
Reported as mock issue 221: http://code.google.com/p/mock/issues/detail?id=221

>>> from unittest.mock import Mock
>>> m = Mock()
>>> m.foo = 3
>>> del m.foo
>>> m.foo = 4
>>> del m.foo
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/compile/py3k-cpython/Lib/unittest/mock.py", line 687, in __delattr__
    raise AttributeError(name)
AttributeError: foo

Suggested change:

Previous:

   def __delattr__(self, name):
       if name in _all_magics and name in type(self).__dict__:
           delattr(type(self), name)
           if name not in self.__dict__:
               # for magic methods that are still MagicProxy objects and
               # 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:
           raise AttributeError(name)
       if obj is not _missing:
           del self._mock_children[name]
       self._mock_children[name] = _deleted


Change:

   def __delattr__(self, name):
       if name in _all_magics and name in type(self).__dict__:
           delattr(type(self), name)
           if name not in self.__dict__:
               # for magic methods that are still MagicProxy objects and
               # not set on the instance itself
               return

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


Incidentally the if ‘obj is not _missing’ line seems superfluous.
History
Date User Action Args
2014-01-13 11:15:02michael.foordsetrecipients: + michael.foord
2014-01-13 11:15:01michael.foordsetmessageid: <1389611701.97.0.048361560176.issue20239@psf.upfronthosting.co.za>
2014-01-13 11:15:01michael.foordlinkissue20239 messages
2014-01-13 11:15:01michael.foordcreate