]> granicus.if.org Git - python/commitdiff
Ensure that isfunction(obj) and (the new) ismethoddescriptor(obj) never
authorTim Peters <tim.peters@gmail.com>
Thu, 20 Sep 2001 05:47:55 +0000 (05:47 +0000)
committerTim Peters <tim.peters@gmail.com>
Thu, 20 Sep 2001 05:47:55 +0000 (05:47 +0000)
both return true.  This restores pydoc's ability to deduce argument lists
for functions and methods coded in Python.

Lib/inspect.py

index c4c15f51dd33c08df583eb074e9f164cc071c7eb..1102c3b2580909cbd078a859287b475dbdecf773 100644 (file)
@@ -58,20 +58,23 @@ def ismethod(object):
     return isinstance(object, types.MethodType)
 
 def ismethoddescriptor(object):
-    """Return true if the object is a method descriptor, and ismethod false.
+    """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 the set of attributes varies.  __name__ is
     usually sensible, and __doc__ often is.
 
-    Methods implemented via descriptors that also pass the ismethod() test
-    return false from the ismethoddescriptor() test, simply because
-    ismethod() is more informative -- you can, e.g., count on having the
-    im_func attribute (etc) when an object passes the latter."""
+    Methods implemented via descriptors that also pass one of the other
+    tests return false from the ismethoddescriptor() test, simply because
+    the other tests promise more -- you can, e.g., count on having the
+    im_func attribute (etc) when an object passes ismethod()."""
     return (hasattr(object, "__get__")
             and not hasattr(object, "__set__") # else it's a data descriptor
             and not ismethod(object)           # mutual exclusion
+            and not isfunction(object)
             and not isclass(object))
 
 def isfunction(object):