-
-
Notifications
You must be signed in to change notification settings - Fork 31.8k
inspect.signature doesn't always return a signature #66000
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
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: 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. |
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. |
Your patch looks good to me. |
New changeset cc0f5d6ccb70 by Yury Selivanov in branch '3.4': New changeset fa5b985f0920 by Yury Selivanov in branch 'default': |
Fixed in 3.4 and 3.5. |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: