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.
This commit is contained in:
parent
c9ed5dc81c
commit
f1d90b965e
|
@ -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):
|
||||
|
|
Loading…
Reference in New Issue