Movatterモバイル変換


[0]ホーム

URL:


homepage

Issue26750

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:Mock autospec does not work with subclasses of property()
Type:behaviorStage:resolved
Components:Library (Lib)Versions:Python 3.6, Python 3.5
process
Status:closedResolution:fixed
Dependencies:Superseder:
Assigned To: berker.peksagNosy List: amaury.forgeotdarc, berker.peksag, gregory.p.smith, michael.foord, python-dev
Priority:normalKeywords:patch

Created on2016-04-13 22:13 byamaury.forgeotdarc, last changed2022-04-11 14:58 byadmin. This issue is nowclosed.

Files
File nameUploadedDescriptionEdit
mock-descriptor.patchamaury.forgeotdarc,2016-04-13 22:13review
mock-descriptor-2.patchamaury.forgeotdarc,2016-05-18 11:47review
Messages (7)
msg263361 -(view)Author: Amaury Forgeot d'Arc (amaury.forgeotdarc)*(Python committer)Date: 2016-04-13 22:13
When patching a class, mock.create_autospec() correctly detects properties and __slot__ attributes, but not subclasses of property() or other kinds of data descriptors.The attached patch detects all data descriptors and patch them the way they should be.
msg265827 -(view)Author: Amaury Forgeot d'Arc (amaury.forgeotdarc)*(Python committer)Date: 2016-05-18 11:47
Updated patch with review comments.
msg272122 -(view)Author: Roundup Robot (python-dev)(Python triager)Date: 2016-08-07 16:06
New changesete947248100ae by Gregory P. Smith in branch '3.5':Issue#26750: unittest.mock.create_autospec() now works properlyhttps://hg.python.org/cpython/rev/e947248100aeNew changeset0bc14c91ef7e by Gregory P. Smith in branch 'default':Issue#26750: unittest.mock.create_autospec() now works properly forhttps://hg.python.org/cpython/rev/0bc14c91ef7e
msg272124 -(view)Author: Berker Peksag (berker.peksag)*(Python committer)Date: 2016-08-07 16:38
Thanks! Is there a reason not to use inspect.isdatadescriptor() instead of _is_data_descriptor()?
msg272215 -(view)Author: Gregory P. Smith (gregory.p.smith)*(Python committer)Date: 2016-08-09 04:40
Probably just Amaury and I forgetting that existed.  Amaury, inspect.isdatadescriptor's implementation is a bit different than this change's _is_data_descriptor.  Thoughts?
msg272842 -(view)Author: Roundup Robot (python-dev)(Python triager)Date: 2016-08-16 06:56
New changeset3ff02380b1bf by Gregory P. Smith in branch '3.5':Issue#26750: use inspect.isdatadescriptor instead of our ownhttps://hg.python.org/cpython/rev/3ff02380b1bfNew changesetd51a66622266 by Gregory P. Smith in branch 'default':Issue#26750: use inspect.isdatadescriptor instead of our ownhttps://hg.python.org/cpython/rev/d51a66622266
msg272997 -(view)Author: Amaury Forgeot d'Arc (amaury.forgeotdarc)*(Python committer)Date: 2016-08-17 22:37
inspect.isdatadescriptor() is better indeed.(I was initially working on an old version of mock.py which does not import inspect, and I did not want to add the dependency there).- inspect uses hasattr(type(obj)) instead of hasatr(obj). This is better, (but does not work for 2.x old-style classes)- my patch tested for __del__... this is completely wrong, it should have been __delete__. oops.inspect.isdatadescriptor() does not test for __delete__. This is insaccurate, but I doubt it will ever matter. This is only possible for Python-defined descriptors, the C implementation always exposes both __set__ and __delete__ when tp_set is filled.IOW, I'm happy with the current state.
History
DateUserActionArgs
2022-04-11 14:58:29adminsetgithub: 70937
2016-08-17 22:40:09gregory.p.smithsetstage: commit review -> resolved
2016-08-17 22:37:19amaury.forgeotdarcsetmessages: +msg272997
2016-08-16 06:56:41python-devsetmessages: +msg272842
2016-08-09 04:40:38gregory.p.smithsetmessages: +msg272215
stage: resolved -> commit review
2016-08-07 16:38:35berker.peksagsetmessages: +msg272124
stage: commit review -> resolved
2016-08-07 16:07:15gregory.p.smithsetstatus: open -> closed
resolution: fixed
stage: patch review -> commit review
2016-08-07 16:06:41python-devsetnosy: +python-dev
messages: +msg272122
2016-08-07 14:43:22gregory.p.smithsetnosy: +gregory.p.smith
2016-05-18 11:49:07berker.peksagsetassignee:berker.peksag
2016-05-18 11:47:01amaury.forgeotdarcsetfiles: +mock-descriptor-2.patch

messages: +msg265827
2016-04-21 11:51:38berker.peksagsetversions: + Python 3.5, Python 3.6
nosy: +berker.peksag

components: + Library (Lib), - Tests
type: enhancement -> behavior
stage: patch review
2016-04-13 22:13:06amaury.forgeotdarccreate
Supported byThe Python Software Foundation,
Powered byRoundup
Copyright © 1990-2022,Python Software Foundation
Legal Statements

[8]ページ先頭

©2009-2026 Movatter.jp