Movatterモバイル変換


[0]ホーム

URL:


homepage

Issue20239

This issue trackerhas been migrated toGitHub, and is currentlyread-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title:Allow repeated deletion of unittest.mock.Mock attributes
Type:behaviorStage:resolved
Components:Versions:Python 3.8, Python 3.7
process
Status:closedResolution:fixed
Dependencies:Superseder:
Assigned To: michael.foordNosy List: cjw296, mariocj89, michael.foord, xtreak
Priority:normalKeywords:patch

Created on2014-01-13 11:15 bymichael.foord, last changed2022-04-11 14:57 byadmin. This issue is nowclosed.

Pull Requests
URLStatusLinkedEdit
PR 11057mergedpablogsal,2018-12-09 21:36
PR 11629mergedmiss-islington,2019-01-21 08:58
PR 11629mergedmiss-islington,2019-01-21 08:58
PR 11629mergedmiss-islington,2019-01-21 08:58
Messages (4)
msg208019 -(view)Author: Michael Foord (michael.foord)*(Python committer)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)*(Python committer)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)*(Python committer)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)*(Python committer)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
DateUserActionArgs
2022-04-11 14:57:56adminsetgithub: 64438
2019-01-21 11:10:03pablogsalsetstatus: open -> closed
resolution: fixed
stage: patch review -> resolved
2019-01-21 09:37:58cjw296setmessages: +msg334117
2019-01-21 08:58:32miss-islingtonsetpull_requests: +pull_request11397
2019-01-21 08:58:27miss-islingtonsetpull_requests: +pull_request11396
2019-01-21 08:58:19miss-islingtonsetpull_requests: +pull_request11395
2019-01-21 08:57:58cjw296setmessages: +msg334114
2018-12-09 21:36:55pablogsalsetkeywords: +patch
stage: needs patch -> patch review
pull_requests: +pull_request10291
2018-12-09 14:17:58xtreaksetnosy: +cjw296,mariocj89,xtreak

messages: +msg331434
versions: + Python 3.7, Python 3.8, - Python 3.3, Python 3.4
2014-01-13 11:15:01michael.foordcreate
Supported byThe Python Software Foundation,
Powered byRoundup
Copyright © 1990-2022,Python Software Foundation
Legal Statements

[8]ページ先頭

©2009-2026 Movatter.jp