bpo-26103: Fix inspect.isdatadescriptor() and a data descriptor definition. (GH-1959)

Look for '__set__' or '__delete__'.
This commit is contained in:
Aaron Hall, MBA 2018-05-20 19:46:42 -04:00 committed by Serhiy Storchaka
parent aef639f626
commit 4054b172ab
5 changed files with 62 additions and 4 deletions

View file

@ -110,7 +110,7 @@ def ismethoddescriptor(object):
def isdatadescriptor(object):
"""Return true if the object is a data descriptor.
Data descriptors have both a __get__ and a __set__ attribute. Examples are
Data descriptors have a __set__ or a __delete__ attribute. Examples are
properties (defined in Python) and getsets and members (defined in C).
Typically, data descriptors will also have __name__ and __doc__ attributes
(properties, getsets, and members have both of these attributes), but this
@ -119,7 +119,7 @@ def isdatadescriptor(object):
# mutual exclusion
return False
tp = type(object)
return hasattr(tp, "__set__") and hasattr(tp, "__get__")
return hasattr(tp, "__set__") or hasattr(tp, "__delete__")
if hasattr(types, 'MemberDescriptorType'):
# CPython and equivalent