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.

classification
Title: Contradiction in definition of "data descriptor" between (dotted lookup behavior/datamodel documentation) and (inspect lib/descriptor how-to)
Type: behavior Stage: resolved
Components: Documentation, Library (Lib) Versions: Python 3.8, Python 3.7, Python 3.6, Python 2.7
process
Status: closed Resolution:
Dependencies: Superseder:
Assigned To: Nosy List: Aaron Hall, Mariatta, cheryl.sabella, chnlior, docs@python, rhettinger, serhiy.storchaka, yselivanov
Priority: normal Keywords:

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:26adminsetgithub: 70291
2021-11-28 12:18:59iritkatriellinkissue31184 superseder
2019-11-15 21:49:05miss-islingtonsetpull_requests: + pull_request16689
2019-10-08 09:19:31hongweipengsetpull_requests: + pull_request16228
2019-03-20 20:16:37Aaron Hallsetstatus: open -> closed
stage: patch review -> resolved
2019-03-20 00:19:34cheryl.sabellasetnosy: + cheryl.sabella
messages: + msg338426
2018-06-10 11:24:31berker.peksaglinkissue32400 superseder
2018-05-20 23:46:44serhiy.storchakasetmessages: + msg317211
2018-05-14 17:18:39serhiy.storchakasetversions: + Python 3.8, - Python 3.5
2017-12-11 23:24:10chnliorsetnosy: + chnlior
messages: + msg308078
2017-09-21 20:45:31serhiy.storchakasetmessages: + msg302721
2017-09-12 03:58:00rhettingersetassignee: rhettinger ->
2017-09-04 14:59:19rhettingersetassignee: rhettinger

nosy: + rhettinger
2017-09-04 04:11:43Aaron Hallsetmessages: + msg301206
2017-06-08 03:49:49Aaron Hallsetmessages: + msg295378
2017-06-06 22:27:44Aaron Hallsetmessages: + msg295307
2017-06-06 18:16:37Mariattasetnosy: + Mariatta
messages: + msg295288
2017-06-06 18:13:41Aaron Hallsetmessages: + msg295287
2017-06-06 07:13:58serhiy.storchakasetversions: + Python 2.7, Python 3.7
nosy: + serhiy.storchaka

messages: + msg295243

assignee: docs@python -> (no value)
stage: needs patch -> patch review
2017-06-05 22:57:49Aaron Hallsetpull_requests: + pull_request2030
2017-06-05 20:43:33Aaron Hallsetmessages: + msg295212
2016-01-14 18:09:16SilentGhostsetversions: - Python 2.7, Python 3.2, Python 3.3, Python 3.4
nosy: + docs@python, yselivanov

assignee: docs@python
components: + Documentation, Library (Lib)
stage: needs patch
2016-01-13 20:56:52Aaron Hallcreate