Return true if the object is a data descriptor. 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, get
(object)
| 217 | and not hasattr(tp, "__delete__")) |
| 218 | |
| 219 | def isdatadescriptor(object): |
| 220 | """Return true if the object is a data descriptor. |
| 221 | |
| 222 | Data descriptors have a __set__ or a __delete__ attribute. Examples are |
| 223 | properties (defined in Python) and getsets and members (defined in C). |
| 224 | Typically, data descriptors will also have __name__ and __doc__ attributes |
| 225 | (properties, getsets, and members have both of these attributes), but this |
| 226 | is not guaranteed.""" |
| 227 | if isclass(object) or ismethod(object) or isfunction(object): |
| 228 | # mutual exclusion |
| 229 | return False |
| 230 | tp = type(object) |
| 231 | return hasattr(tp, "__set__") or hasattr(tp, "__delete__") |
| 232 | |
| 233 | if hasattr(types, 'MemberDescriptorType'): |
| 234 | # CPython and equivalent |
no test coverage detected
searching dependent graphs…