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

Created on 2016-01-13 20:56 by Aaron Hall, last changed 2017-09-21 20:45 by serhiy.storchaka.

Pull Requests
URL Status Linked Edit
PR 1959 open Aaron Hall, 2017-06-05 22:57
Messages (9)
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 Wijaya (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?
History
Date User Action Args
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