summaryrefslogtreecommitdiffstats
path: root/Lib/inspect.py
diff options
context:
space:
mode:
authorTim Peters <tim.peters@gmail.com>2001-09-20 05:47:55 (GMT)
committerTim Peters <tim.peters@gmail.com>2001-09-20 05:47:55 (GMT)
commitf1d90b965e50c17d09535c1f740942dde3d8a294 (patch)
tree2996aa9005fb3a0728a2dcd0087eba187e34aabc /Lib/inspect.py
parentc9ed5dc81c143b70203905fe89ece96d0dcea1e3 (diff)
downloadcpython-f1d90b965e50c17d09535c1f740942dde3d8a294.zip
cpython-f1d90b965e50c17d09535c1f740942dde3d8a294.tar.gz
cpython-f1d90b965e50c17d09535c1f740942dde3d8a294.tar.bz2
Ensure that isfunction(obj) and (the new) ismethoddescriptor(obj) never
both return true. This restores pydoc's ability to deduce argument lists for functions and methods coded in Python.
Diffstat (limited to 'Lib/inspect.py')
-rw-r--r--Lib/inspect.py13
1 files changed, 8 insertions, 5 deletions
diff --git a/Lib/inspect.py b/Lib/inspect.py
index c4c15f5..1102c3b 100644
--- a/Lib/inspect.py
+++ b/Lib/inspect.py
@@ -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):