summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTerry Jan Reedy <tjreedy@udel.edu>2012-06-03 04:58:36 (GMT)
committerTerry Jan Reedy <tjreedy@udel.edu>2012-06-03 04:58:36 (GMT)
commite93bc51b5982c329a6065eb83ac1dea5efb02bd7 (patch)
tree3262c8d79c5d651375e6d0763177fee9cf0bdb8e
parentf0775131f9952a96260cea5943725ac35c629db0 (diff)
downloadcpython-e93bc51b5982c329a6065eb83ac1dea5efb02bd7.zip
cpython-e93bc51b5982c329a6065eb83ac1dea5efb02bd7.tar.gz
cpython-e93bc51b5982c329a6065eb83ac1dea5efb02bd7.tar.bz2
Issue 12510: Expand 2 bare excepts. Improve comments. Change deceptive name
'name' to 'expression' as the latter is what the string actually represents. The bug in this issue was only catching NameError and AttributeError when evaluating an expression that was not necessarily a name.
-rw-r--r--Lib/idlelib/CallTips.py30
1 files changed, 16 insertions, 14 deletions
diff --git a/Lib/idlelib/CallTips.py b/Lib/idlelib/CallTips.py
index ce09983..d533ce1 100644
--- a/Lib/idlelib/CallTips.py
+++ b/Lib/idlelib/CallTips.py
@@ -71,16 +71,16 @@ class CallTips:
if not sur_paren:
return
hp.set_index(sur_paren[0])
- name = hp.get_expression()
- if not name or (not evalfuncs and name.find('(') != -1):
+ expression = hp.get_expression()
+ if not expression or (not evalfuncs and expression.find('(') != -1):
return
- arg_text = self.fetch_tip(name)
+ arg_text = self.fetch_tip(expression)
if not arg_text:
return
self.calltip = self._make_calltip_window()
self.calltip.showtip(arg_text, sur_paren[0], sur_paren[1])
- def fetch_tip(self, name):
+ def fetch_tip(self, expression):
"""Return the argument list and docstring of a function or class
If there is a Python subprocess, get the calltip there. Otherwise,
@@ -96,25 +96,27 @@ class CallTips:
"""
try:
rpcclt = self.editwin.flist.pyshell.interp.rpcclt
- except:
+ except AttributeError:
rpcclt = None
if rpcclt:
return rpcclt.remotecall("exec", "get_the_calltip",
- (name,), {})
+ (expression,), {})
else:
- entity = self.get_entity(name)
+ entity = self.get_entity(expression)
return get_arg_text(entity)
- def get_entity(self, name):
- "Lookup name in a namespace spanning sys.modules and __main.dict__"
- if name:
+ def get_entity(self, expression):
+ """Return the object corresponding to expression evaluated
+ in a namespace spanning sys.modules and __main.dict__.
+ """
+ if expression:
namespace = sys.modules.copy()
namespace.update(__main__.__dict__)
try:
- return eval(name, namespace)
- # any exception is possible if evalfuncs True in open_calltip
- # at least Syntax, Name, Attribute, Index, and Key E. if not
- except:
+ return eval(expression, namespace)
+ except BaseException:
+ # An uncaught exception closes idle, and eval can raise any
+ # exception, especially if user classes are involved.
return None
def _find_constructor(class_ob):