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
(object)
| 328 | return hasattr(tp, "__get__") and not hasattr(tp, "__set__") |
| 329 | |
| 330 | def isdatadescriptor(object): |
| 331 | """Return true if the object is a data descriptor. |
| 332 | |
| 333 | Data descriptors have a __set__ or a __delete__ attribute. Examples are |
| 334 | properties (defined in Python) and getsets and members (defined in C). |
| 335 | Typically, data descriptors will also have __name__ and __doc__ attributes |
| 336 | (properties, getsets, and members have both of these attributes), but this |
| 337 | is not guaranteed.""" |
| 338 | if isclass(object) or ismethod(object) or isfunction(object): |
| 339 | # mutual exclusion |
| 340 | return False |
| 341 | tp = type(object) |
| 342 | return hasattr(tp, "__set__") or hasattr(tp, "__delete__") |
| 343 | |
| 344 | if hasattr(types, 'MemberDescriptorType'): |
| 345 | # CPython and equivalent |
no test coverage detected