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.

Author Aaron Hall
Recipients Aaron Hall
Date 2016-01-13.20:56:51
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1452718612.1.0.925403449689.issue26103@psf.upfronthosting.co.za>
In-reply-to
Content
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.
History
Date User Action Args
2016-01-13 20:56:52Aaron Hallsetrecipients: + Aaron Hall
2016-01-13 20:56:52Aaron Hallsetmessageid: <1452718612.1.0.925403449689.issue26103@psf.upfronthosting.co.za>
2016-01-13 20:56:52Aaron Halllinkissue26103 messages
2016-01-13 20:56:51Aaron Hallcreate