MCPcopy Index your code
hub / github.com/python/cpython / ismethoddescriptor

Function ismethoddescriptor

Lib/inspect.py:196–217  ·  view source on GitHub ↗

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 or a __delete__ attri

(object)

Source from the content-addressed store, hash-verified

194 return ismodule(object) and hasattr(object, "__path__")
195
196def ismethoddescriptor(object):
197 """Return true if the object is a method descriptor.
198
199 But not if ismethod() or isclass() or isfunction() are true.
200
201 This is new in Python 2.2, and, for example, is true of int.__add__.
202 An object passing this test has a __get__ attribute, but not a
203 __set__ attribute or a __delete__ attribute. Beyond that, the set
204 of attributes varies; __name__ is usually sensible, and __doc__
205 often is.
206
207 Methods implemented via descriptors that also pass one of the other
208 tests return false from the ismethoddescriptor() test, simply because
209 the other tests promise more -- you can, e.g., count on having the
210 __func__ attribute (etc) when an object passes ismethod()."""
211 if isclass(object) or ismethod(object) or isfunction(object):
212 # mutual exclusion
213 return False
214 tp = type(object)
215 return (hasattr(tp, "__get__")
216 and not hasattr(tp, "__set__")
217 and not hasattr(tp, "__delete__"))
218
219def isdatadescriptor(object):
220 """Return true if the object is a data descriptor.

Callers 3

isroutineFunction · 0.85
_finddocFunction · 0.85
_signature_is_builtinFunction · 0.85

Calls 3

isclassFunction · 0.85
ismethodFunction · 0.85
isfunctionFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…