[Python-Dev] how to inspect if something includes a bound first param (original) (raw)
Terry Reedy tjreedy at udel.edu
Wed Feb 25 04:21:29 CET 2015
- Previous message: [Python-Dev] how to inspect if something includes a bound first param
- Next message: [Python-Dev] how to inspect if something includes a bound first param
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
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
- Previous message: [Python-Dev] how to inspect if something includes a bound first param
- Next message: [Python-Dev] how to inspect if something includes a bound first param
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]