MCPcopy Create free account
hub / github.com/RT-Thread/env-windows / ismethoddescriptor

Function ismethoddescriptor

tools/python-3.11.9-amd64/Lib/inspect.py:310–328  ·  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, but beyond that

(object)

Source from the content-addressed store, hash-verified

308 return isinstance(object, types.MethodType)
309
310def 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
330def isdatadescriptor(object):
331 """Return true if the object is a data descriptor.

Callers 3

isroutineFunction · 0.85
_finddocFunction · 0.85
_signature_is_builtinFunction · 0.85

Calls 4

isclassFunction · 0.85
ismethodFunction · 0.85
isfunctionFunction · 0.85
typeClass · 0.50

Tested by

no test coverage detected