New submission from Claudiu Popa:

Hello. I noticed the following behaviour while working with xmlrpc proxy 
methods.

>>> import inspect, xmlrpc.client
>>> proxy = xmlrpc.client.ServerProxy('http://localhost:8000')
>>> proxy.mul
<xmlrpc.client._Method object at 0x03B0C890>
>>> inspect.signature(proxy.mul)
<xmlrpc.client._Method object at 0x03B0CC90>
>>>


Now, according to the documentation, inspect.signature should return a 
signature or fail, but in this case it returns the actual object, which is 
misleading at least. This happens because _Method implements a proxy 
__getattr__, any accessed attribute becoming again a _Method. At the same time, 
inspect.signature happily uses 

try:
   obj.__signature__
except AttributeError:
   ...

to obtain the signature, if present.

The attached patch checks if __signature__ is an actual Signature object. I 
searched, but couldn't find any, if __signature__ can be anything, so I hope 
that this approach works.

----------
components: Library (Lib)
files: inspect_signature.patch
keywords: patch
messages: 220936
nosy: Claudiu.Popa, yselivanov
priority: normal
severity: normal
status: open
title: inspect.signature doesn't always return a signature
type: enhancement
versions: Python 3.5
Added file: http://bugs.python.org/file35682/inspect_signature.patch

_______________________________________
Python tracker <rep...@bugs.python.org>
<http://bugs.python.org/issue21801>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to