[Python-Dev] how to inspect if something includes a bound first param (original) (raw)
Gregory P. Smith greg at krypto.org
Wed Feb 25 02:56:21 CET 2015
- Previous message: [Python-Dev] ?s re documentation of Python features
- Next message: [Python-Dev] how to inspect if something includes a bound first param
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
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 -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://mail.python.org/pipermail/python-dev/attachments/20150225/4a6f23b1/attachment-0001.html>
- Previous message: [Python-Dev] ?s re documentation of Python features
- Next message: [Python-Dev] how to inspect if something includes a bound first param
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]