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
IDLE crashes when KeyError is raised during calltip generation #82870
Comments
When the following program has been input (into 32 bit 3.8.0 Python running on windows 10), all IDLE processes and windows will immediately and irrevocably hang the instant the open parentheses at the end of the statement "Object(" is rendered. However that's just my 90% sure guess of the cause, based on >>> if 1:
from idlelib.calltip import get_argspec
class Type(type):
__class__ = property((__class__:={}).__getitem__,__class__.__setitem__)
class Object(metaclass=Type):
__slots__ = '__class__'
get_argspec(Object)
Traceback (most recent call last):
File "<pyshell#41>", line 7, in <module>
get_argspec(Object)
File "C:\Python38\lib\idlelib\calltip.py", line 141, in get_argspec
argspec = str(inspect.signature(fob))
File "C:\Python38\lib\inspect.py", line 3093, in signature
return Signature.from_callable(obj, follow_wrapped=follow_wrapped)
File "C:\Python38\lib\inspect.py", line 2842, in from_callable
return _signature_from_callable(obj, sigcls=cls,
File "C:\Python38\lib\inspect.py", line 2218, in _signature_from_callable
if isinstance(obj, types.MethodType):
KeyError: <class '__main__.Object'> |
Since isinstance(Object.__call__, types.MethodType) is False, the 'fob' in 'inspect.signature(fob)' is Object. (See the initial get_argspec code.) Indeed, 'inspect.signature(Object)' results in the traceback following inspect.signature(fob) and 'isinstance(Object, types.MethodType)' results in the last line thereof. Not returning 'False' strikes me as maybe a bug in 'isinstance'. Have you opened a report for this? Directly importing and executing idlelib code is not supported (its is 'private'), but entering 'Object(' to cause IDLE to make the same call is. And the result is worse than the exception. The IDLE gui process hangs, waiting for the response from the socket connection to the user code process that never comes. This is clearly a bug, regardless of whether the user code is buggy. The relevant section of get_argspec is
Signature() is documented as returning either ValueError or TypeError, and with the 'bug' in isinstance, others are possible. So any error should be caught. (The default of falling through and checking for a docstring signature is correct.) |
Further experiments suggest a fix for the hang, which is not specific to this example. See new issue bpo-38695. |
See PR #61354 with a fix for the uncaught exception in getargspec(). |
get_argspec accesses the user object 3 times. The first, ob.__call__ was already wrapped in try-except. The second, signature(ob or ob.__call) is wrapped by this issue. It also adds a new test based on Dan's example. The third is (ob or ob.__call__).__doc__. I did not wrap this because I could not create an example for which this fails. There seems to be some special casing of this special attribute so that its default is None. I opened bpo-40180 for the isinstance bug and bpo-40181 for further get_argspec changes, in particular, removing the positional-only '/' note. |
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: