mirror of
https://github.com/python/cpython.git
synced 2025-11-25 04:34:37 +00:00
bpo-26103: Fix inspect.isdatadescriptor() and a data descriptor definition. (GH-1959)
Look for '__set__' or '__delete__'.
This commit is contained in:
parent
aef639f626
commit
4054b172ab
5 changed files with 62 additions and 4 deletions
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue