[Python-Dev] how to inspect if something includes a bound first param

Terry Reedy tjreedy at udel.edu
Wed Feb 25 04:21:29 CET 2015


On 2/24/2015 8:56 PM, Gregory P. Smith wrote:
> inspect.getargspec(method) and inspect.signature(method) both include
> the 'self' parameter but how are we to figure out from method itself
> that it is actually bound and that its first parameter is expected to be
> a bound instance?

This seems like a python-list question.

> So far I've come up with:
> /inspect.ismethod(method) or inspect.ismethoddescriptor(method)/
>
> But that is still not quite right as it remains False in 3.4 for the
> simple case of:
>
>  >>> class A:
> ...  def x(self):
> ...    pass
> ...
>  >>> inspect.ismethod(A.x)
> False
>  >>> inspect.ismethoddescriptor(A.x)
> False

These are correct.  A.x is the function resulting from execution of the 
def statement.

 >>> type(A.x)
<class 'function'>

This is different from 2.x.  If you call the function as a function, 
there is no requirement on its argument, and no binding.

 >>> A.x(3)  # returns None
 >>>

-- 
Terry Jan Reedy



More information about the Python-Dev mailing list