
This issue trackerhas been migrated toGitHub, and is currentlyread-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.
Created on2014-01-13 11:15 bymichael.foord, last changed2022-04-11 14:57 byadmin. This issue is nowclosed.
| Pull Requests | |||
|---|---|---|---|
| URL | Status | Linked | Edit |
| PR 11057 | merged | pablogsal,2018-12-09 21:36 | |
| PR 11629 | merged | miss-islington,2019-01-21 08:58 | |
| PR 11629 | merged | miss-islington,2019-01-21 08:58 | |
| PR 11629 | merged | miss-islington,2019-01-21 08:58 | |
| Messages (4) | |||
|---|---|---|---|
| msg208019 -(view) | Author: Michael Foord (michael.foord)*![]() | Date: 2014-01-13 11:15 | |
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.fooTraceback (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: fooSuggested 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] = _deletedChange: 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] = _deletedIncidentally the if ‘obj is not _missing’ line seems superfluous. | |||
| msg331434 -(view) | Author: Karthikeyan Singaravelan (xtreak)*![]() | Date: 2018-12-09 14:17 | |
I find this to be a reasonable behavior as with normal objects that support setting the attribute after deletion. It also seems to be an easy issue since @michael.foord has already attached the patch for this from the original report. The patch also also causes no test failure on master and a unit test can be added for the behavior once confirmed. | |||
| msg334114 -(view) | Author: Chris Withers (cjw296)*![]() | Date: 2019-01-21 08:57 | |
New changeset222d303ade8aadf0adcae5190fac603bdcafe3f0 by Chris Withers (Pablo Galindo) in branch 'master':bpo-20239: Allow repeated deletion of unittest.mock.Mock attributes (#11057)https://github.com/python/cpython/commit/222d303ade8aadf0adcae5190fac603bdcafe3f0 | |||
| msg334117 -(view) | Author: Chris Withers (cjw296)*![]() | Date: 2019-01-21 09:37 | |
New changesetd358a8cda75446a8e0b5d99149f709395d5eae19 by Chris Withers (Miss Islington (bot)) in branch '3.7':bpo-20239: Allow repeated deletion of unittest.mock.Mock attributes (GH-11629)https://github.com/python/cpython/commit/d358a8cda75446a8e0b5d99149f709395d5eae19 | |||
| History | |||
|---|---|---|---|
| Date | User | Action | Args |
| 2022-04-11 14:57:56 | admin | set | github: 64438 |
| 2019-01-21 11:10:03 | pablogsal | set | status: open -> closed resolution: fixed stage: patch review -> resolved |
| 2019-01-21 09:37:58 | cjw296 | set | messages: +msg334117 |
| 2019-01-21 08:58:32 | miss-islington | set | pull_requests: +pull_request11397 |
| 2019-01-21 08:58:27 | miss-islington | set | pull_requests: +pull_request11396 |
| 2019-01-21 08:58:19 | miss-islington | set | pull_requests: +pull_request11395 |
| 2019-01-21 08:57:58 | cjw296 | set | messages: +msg334114 |
| 2018-12-09 21:36:55 | pablogsal | set | keywords: +patch stage: needs patch -> patch review pull_requests: +pull_request10291 |
| 2018-12-09 14:17:58 | xtreak | set | nosy: +cjw296,mariocj89,xtreak messages: +msg331434 versions: + Python 3.7, Python 3.8, - Python 3.3, Python 3.4 |
| 2014-01-13 11:15:01 | michael.foord | create | |