A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://mail.python.org/pipermail/python-dev/2015-February/138547.html below:

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

[Python-Dev] how to inspect if something includes a bound first param [Python-Dev] how to inspect if something includes a bound first paramGregory P. Smith greg at krypto.org
Wed Feb 25 02:56:21 CET 2015
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>
More information about the Python-Dev mailing list

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4