Movatterモバイル変換


[0]ホーム

URL:


homepage

Issue21801

This issue trackerhas been migrated toGitHub, and is currentlyread-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title:inspect.signature doesn't always return a signature
Type:enhancementStage:resolved
Components:Library (Lib)Versions:Python 3.4, Python 3.5
process
Status:closedResolution:fixed
Dependencies:Superseder:
Assigned To: yselivanovNosy List: Claudiu.Popa, larry, ncoghlan, python-dev, yselivanov
Priority:normalKeywords:needs review, patch

Created on2014-06-18 12:41 byClaudiu.Popa, last changed2022-04-11 14:58 byadmin. This issue is nowclosed.

Files
File nameUploadedDescriptionEdit
inspect_signature.patchClaudiu.Popa,2014-06-18 12:41review
issue21801.patchyselivanov,2014-06-20 18:13review
Messages (5)
msg220936 -(view)Author: PCManticore (Claudiu.Popa)*(Python triager)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)*(Python committer)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)*(Python triager)Date: 2014-06-20 19:16
Your patch looks good to me.
msg221368 -(view)Author: Roundup Robot (python-dev)(Python triager)Date: 2014-06-23 17:24
New changesetcc0f5d6ccb70 by Yury Selivanov in branch '3.4':inspect: Validate that __signature__ is None or an instance of Signature.http://hg.python.org/cpython/rev/cc0f5d6ccb70New changesetfa5b985f0920 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)*(Python committer)Date: 2014-06-23 17:24
Fixed in 3.4 and 3.5.Thanks for the bug report!
History
DateUserActionArgs
2022-04-11 14:58:05adminsetgithub: 66000
2014-06-23 17:24:36yselivanovsetmessages: +msg221369
2014-06-23 17:24:02python-devsetstatus: open -> closed

nosy: +python-dev
messages: +msg221368

resolution: fixed
stage: resolved
2014-06-20 20:06:06yselivanovsetkeywords: +needs review
assignee:yselivanov
versions: + Python 3.4
2014-06-20 19:16:39Claudiu.Popasetmessages: +msg221114
2014-06-20 18:13:56yselivanovsetfiles: +issue21801.patch
nosy: +ncoghlan,larry
messages: +msg221103

2014-06-18 12:41:45Claudiu.Popacreate
Supported byThe Python Software Foundation,
Powered byRoundup
Copyright © 1990-2022,Python Software Foundation
Legal Statements

[8]ページ先頭

©2009-2026 Movatter.jp