Issue 26103: Contradiction in definition of "data descriptor" between (dotted lookup behavior/datamodel documentation) and (inspect lib/descriptor how-to) (original) (raw)

Created on 2016-01-13 20:56 by Aaron Hall, last changed 2022-04-11 14:58 by admin. This issue is now closed.

Pull Requests
URL Status Linked Edit
PR 1959 merged Aaron Hall,2017-06-05 22:57
PR 16645 merged hongweipeng,2019-10-08 09:19
PR 17180 merged miss-islington,2019-11-15 21:49
Messages (12)
msg258168 - (view) Author: Aaron Hall (Aaron Hall) * Date: 2016-01-13 20:56
Based on the data-model documentation (https://docs.python.org/2/reference/datamodel.html#invoking-descriptors) and the dotted lookup behavior, the follow definitions are correct: "If the descriptor defines __set__() and/or __delete__(), it is a data descriptor; if it defines neither, it is a non-data descriptor." def has_data_descriptor_attrs(obj): return set(['__set__', '__delete__']) & set(dir(obj)) def is_data_descriptor(obj): return bool(has_data_descriptor_attrs(obj)) However, the inspect module has the following, which is also reflected in the descriptor how-to (https://docs.python.org/2/howto/descriptor.html#descriptor-protocol): "If an object defines both __get__() and __set__(), it is considered a data descriptor." def isdatadescriptor(object): """Return true if the object is a data descriptor. Data descriptors have both a __get__ and a __set__ attribute...""" if isclass(object) or ismethod(object) or isfunction(object): # mutual exclusion return False tp = type(object) return hasattr(tp, "__set__") and hasattr(tp, "__get__") I'm willing to sign a contributor release and fix myself.
msg295212 - (view) Author: Aaron Hall (Aaron Hall) * Date: 2017-06-05 20:43
Bumping this - I intend to work on this next, if no objections.
msg295243 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2017-06-06 07:13
This isn't just a documentation issue since it fixes inspect.isdatadescriptor(). I confirm that the new implementation better matches the C code. LGTM, but needed tests for inspect.isdatadescriptor() and a Misc/NEWS entry.
msg295287 - (view) Author: Aaron Hall (Aaron Hall) * Date: 2017-06-06 18:13
Added news, working on tests
msg295288 - (view) Author: Mariatta (Mariatta) * (Python committer) Date: 2017-06-06 18:16
Please also add yourself to Misc/ACKS.
msg295307 - (view) Author: Aaron Hall (Aaron Hall) * Date: 2017-06-06 22:27
> Please also add yourself to Misc/ACKS. Done!
msg295378 - (view) Author: Aaron Hall (Aaron Hall) * Date: 2017-06-08 03:49
I tweaked the docs a little more this morning, but I believe I am done making any further changes unless so requested. This issue doesn't say it's assigned to anyone. Is there anything else that needs to happen here?
msg301206 - (view) Author: Aaron Hall (Aaron Hall) * Date: 2017-09-04 04:11
Serhiy, Not sure what else needs to be done to wrap this up. All checks are passing on the pull request. Thoughts?
msg302721 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2017-09-21 20:45
The only question is remained -- should *data descriptors* be *descriptors*? I.e. is the __get__ method required for data descriptors?
msg308078 - (view) Author: Lior Cohen (chnlior) Date: 2017-12-11 23:24
Joining @Serhiy Storchaka last question. Is the __get__ method existance is a must be a data descriptor? According to the C implementation in descrobject.h ``` #define PyDescr_IsData(d) (Py_TYPE(d)->tp_descr_set != NULL) #endif ``` the answer is No. Does this C code reflect the true definition?
msg317211 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2018-05-20 23:46
New changeset 4054b172ab59054715a2aaf4979bd84ac23e3ada by Serhiy Storchaka (Aaron Hall, MBA) in branch 'master': bpo-26103: Fix inspect.isdatadescriptor() and a data descriptor definition. (GH-1959) https://github.com/python/cpython/commit/4054b172ab59054715a2aaf4979bd84ac23e3ada
msg338426 - (view) Author: Cheryl Sabella (cheryl.sabella) * (Python committer) Date: 2019-03-20 00:19
It looks like this issue can be closed now that it's merged?
History
Date User Action Args
2022-04-11 14:58:26 admin set github: 70291
2021-11-28 12🔞59 iritkatriel link issue31184 superseder
2019-11-15 21:49:05 miss-islington set pull_requests: + <pull%5Frequest16689>
2019-10-08 09:19:31 hongweipeng set pull_requests: + <pull%5Frequest16228>
2019-03-20 20:16:37 Aaron Hall set status: open -> closedstage: patch review -> resolved
2019-03-20 00:19:34 cheryl.sabella set nosy: + cheryl.sabellamessages: +
2018-06-10 11:24:31 berker.peksag link issue32400 superseder
2018-05-20 23:46:44 serhiy.storchaka set messages: +
2018-05-14 17🔞39 serhiy.storchaka set versions: + Python 3.8, - Python 3.5
2017-12-11 23:24:10 chnlior set nosy: + chnliormessages: +
2017-09-21 20:45:31 serhiy.storchaka set messages: +
2017-09-12 03:58:00 rhettinger set assignee: rhettinger ->
2017-09-04 14:59:19 rhettinger set assignee: rhettingernosy: + rhettinger
2017-09-04 04:11:43 Aaron Hall set messages: +
2017-06-08 03:49:49 Aaron Hall set messages: +
2017-06-06 22:27:44 Aaron Hall set messages: +
2017-06-06 18:16:37 Mariatta set nosy: + Mariattamessages: +
2017-06-06 18:13:41 Aaron Hall set messages: +
2017-06-06 07:13:58 serhiy.storchaka set versions: + Python 2.7, Python 3.7nosy: + serhiy.storchakamessages: + assignee: docs@python -> (no value)stage: needs patch -> patch review
2017-06-05 22:57:49 Aaron Hall set pull_requests: + <pull%5Frequest2030>
2017-06-05 20:43:33 Aaron Hall set messages: +
2016-01-14 18:09:16 SilentGhost set versions: - Python 2.7, Python 3.2, Python 3.3, Python 3.4nosy: + docs@python, yselivanovassignee: docs@pythoncomponents: + Documentation, Library (Lib)stage: needs patch
2016-01-13 20:56:52 Aaron Hall create