Return true if the object is a method descriptor. But not if ismethod() or isclass() or isfunction() are true. This is new in Python 2.2, and, for example, is true of int.__add__. An object passing this test has a __get__ attribute but not a __set__ attribute, but beyond that
(object)
| 308 | return isinstance(object, types.MethodType) |
| 309 | |
| 310 | def ismethoddescriptor(object): |
| 311 | """Return true if the object is a method descriptor. |
| 312 | |
| 313 | But not if ismethod() or isclass() or isfunction() are true. |
| 314 | |
| 315 | This is new in Python 2.2, and, for example, is true of int.__add__. |
| 316 | An object passing this test has a __get__ attribute but not a __set__ |
| 317 | attribute, but beyond that the set of attributes varies. __name__ is |
| 318 | usually sensible, and __doc__ often is. |
| 319 | |
| 320 | Methods implemented via descriptors that also pass one of the other |
| 321 | tests return false from the ismethoddescriptor() test, simply because |
| 322 | the other tests promise more -- you can, e.g., count on having the |
| 323 | __func__ attribute (etc) when an object passes ismethod().""" |
| 324 | if isclass(object) or ismethod(object) or isfunction(object): |
| 325 | # mutual exclusion |
| 326 | return False |
| 327 | tp = type(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. |
no test coverage detected