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?
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 >>> inspect.signature(A.x).parameters mappingproxy(OrderedDict([('self', <Parameter at 0x7fdd8188eae8 'self'>)])) >>> inspect.getargspec(A.x) ArgSpec(args=['self'], varargs=None, keywords=None, defaults=None) The above works if use it on object.__init__, but not on a method of an uninstantiated class. (it also works on the instantiated A().x) Checking if *(inspect.isfunction(method) and method.__qualname__ != method.__name__)* perhaps but that seems questionably hacky. Is there a right way to do this via the inspect module that I've missed? It seems like that'd be nice, but I don't feel like I know enough to write up a feature request for it yet. (granted I hope nobody *wants* to write code that does this...) -gps
_______________________________________________ Python-Dev mailing list Python-Dev@python.org https://mail.python.org/mailman/listinfo/python-dev Unsubscribe: https://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com