Changeset 391 for python/trunk/Lib/idlelib/CallTips.py
- Timestamp:
- Mar 19, 2014, 11:31:01 PM (11 years ago)
- Location:
- python/trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
python/trunk
-
Property svn:mergeinfo
set to
/python/vendor/Python-2.7.6 merged eligible /python/vendor/current merged eligible
-
Property svn:mergeinfo
set to
-
python/trunk/Lib/idlelib/CallTips.py
r2 r391 10 10 import types 11 11 12 import CallTipWindow13 from HyperParser import HyperParser12 from idlelib import CallTipWindow 13 from idlelib.HyperParser import HyperParser 14 14 15 15 import __main__ … … 72 72 return 73 73 hp.set_index(sur_paren[0]) 74 name= hp.get_expression()75 if not name or (not evalfuncs and name.find('(') != -1):76 return 77 arg_text = self.fetch_tip( name)74 expression = hp.get_expression() 75 if not expression or (not evalfuncs and expression.find('(') != -1): 76 return 77 arg_text = self.fetch_tip(expression) 78 78 if not arg_text: 79 79 return … … 81 81 self.calltip.showtip(arg_text, sur_paren[0], sur_paren[1]) 82 82 83 def fetch_tip(self, name):83 def fetch_tip(self, expression): 84 84 """Return the argument list and docstring of a function or class 85 85 … … 97 97 try: 98 98 rpcclt = self.editwin.flist.pyshell.interp.rpcclt 99 except :99 except AttributeError: 100 100 rpcclt = None 101 101 if rpcclt: 102 102 return rpcclt.remotecall("exec", "get_the_calltip", 103 ( name,), {})103 (expression,), {}) 104 104 else: 105 entity = self.get_entity( name)105 entity = self.get_entity(expression) 106 106 return get_arg_text(entity) 107 107 108 def get_entity(self, name): 109 "Lookup name in a namespace spanning sys.modules and __main.dict__" 110 if name: 108 def get_entity(self, expression): 109 """Return the object corresponding to expression evaluated 110 in a namespace spanning sys.modules and __main.dict__. 111 """ 112 if expression: 111 113 namespace = sys.modules.copy() 112 114 namespace.update(__main__.__dict__) 113 115 try: 114 return eval(name, namespace) 115 except (NameError, AttributeError): 116 return eval(expression, namespace) 117 except BaseException: 118 # An uncaught exception closes idle, and eval can raise any 119 # exception, especially if user classes are involved. 116 120 return None 117 121 … … 128 132 129 133 def get_arg_text(ob): 130 """Get a string describing the arguments for the given object""" 134 """Get a string describing the arguments for the given object, 135 only if it is callable.""" 131 136 arg_text = "" 132 if ob is not None :137 if ob is not None and hasattr(ob, '__call__'): 133 138 arg_offset = 0 134 139 if type(ob) in (types.ClassType, types.TypeType): … … 159 164 items.append("***") 160 165 arg_text = ", ".join(items) 161 arg_text = "(%s)" % re.sub(" \.\d+", "<tuple>", arg_text)166 arg_text = "(%s)" % re.sub("(?<!\d)\.\d+", "<tuple>", arg_text) 162 167 # See if we can use the docstring 163 168 doc = getattr(ob, "__doc__", "") … … 219 224 TC, tc.t1, tc.t2, tc.t3, tc.t4, tc.t5, tc.t6, tc.t7) 220 225 221 test(tests) 226 # test(tests) 227 from unittest import main 228 main('idlelib.idle_test.test_calltips', verbosity=2, exit=False)
Note:
See TracChangeset
for help on using the changeset viewer.