Issue21801
Created on 2014-06-18 12:41 by Claudiu.Popa, last changed 2022-04-11 14:58 by admin. This issue is now closed.
| Files | ||||
|---|---|---|---|---|
| File name | Uploaded | Description | Edit | |
| inspect_signature.patch | Claudiu.Popa, 2014-06-18 12:41 | review | ||
| issue21801.patch | yselivanov, 2014-06-20 18:13 | review | ||
| Messages (5) | |||
|---|---|---|---|
| msg220936 - (view) | Author: PCManticore (Claudiu.Popa) * | Date: 2014-06-18 12:41 | |
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.
|
|||
| msg221103 - (view) | Author: Yury Selivanov (yselivanov) * | Date: 2014-06-20 18:13 | |
This behaviour is indeed a bug. However, I think that the solution you propose is wrong. If we ignore invalid contents of __signature__ we are masking a bug or incorrect behaviour. In this case, you should have checked the requested attribute name in '__getattr__', and return something other than _Method, if it is a '__signature__'. Please find attached a patch, that checks if __signature__ is an instance of Signature class, and raises a TypeError if it isn't. |
|||
| msg221114 - (view) | Author: PCManticore (Claudiu.Popa) * | Date: 2014-06-20 19:16 | |
Your patch looks good to me. |
|||
| msg221368 - (view) | Author: Roundup Robot (python-dev) | Date: 2014-06-23 17:24 | |
New changeset cc0f5d6ccb70 by Yury Selivanov in branch '3.4': inspect: Validate that __signature__ is None or an instance of Signature. http://hg.python.org/cpython/rev/cc0f5d6ccb70 New changeset fa5b985f0920 by Yury Selivanov in branch 'default': inspect: Validate that __signature__ is None or an instance of Signature. http://hg.python.org/cpython/rev/fa5b985f0920 |
|||
| msg221369 - (view) | Author: Yury Selivanov (yselivanov) * | Date: 2014-06-23 17:24 | |
Fixed in 3.4 and 3.5. Thanks for the bug report! |
|||
| History | |||
|---|---|---|---|
| Date | User | Action | Args |
| 2022-04-11 14:58:05 | admin | set | github: 66000 |
| 2014-06-23 17:24:36 | yselivanov | set | messages: + msg221369 |
| 2014-06-23 17:24:02 | python-dev | set | status: open -> closed nosy:
+ python-dev resolution: fixed |
| 2014-06-20 20:06:06 | yselivanov | set | keywords:
+ needs review assignee: yselivanov versions: + Python 3.4 |
| 2014-06-20 19:16:39 | Claudiu.Popa | set | messages: + msg221114 |
| 2014-06-20 18:13:56 | yselivanov | set | files:
+ issue21801.patch nosy: + ncoghlan, larry messages: + msg221103 |
| 2014-06-18 12:41:45 | Claudiu.Popa | create | |