Ignore:
Timestamp:
Mar 19, 2014, 11:31:01 PM (11 years ago)
Author:
dmik
Message:

python: Merge vendor 2.7.6 to trunk.

Location:
python/trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • python/trunk

  • python/trunk/Lib/idlelib/CallTips.py

    r2 r391  
    1010import types
    1111
    12 import CallTipWindow
    13 from HyperParser import HyperParser
     12from idlelib import CallTipWindow
     13from idlelib.HyperParser import HyperParser
    1414
    1515import __main__
     
    7272            return
    7373        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)
    7878        if not arg_text:
    7979            return
     
    8181        self.calltip.showtip(arg_text, sur_paren[0], sur_paren[1])
    8282
    83     def fetch_tip(self, name):
     83    def fetch_tip(self, expression):
    8484        """Return the argument list and docstring of a function or class
    8585
     
    9797        try:
    9898            rpcclt = self.editwin.flist.pyshell.interp.rpcclt
    99         except:
     99        except AttributeError:
    100100            rpcclt = None
    101101        if rpcclt:
    102102            return rpcclt.remotecall("exec", "get_the_calltip",
    103                                      (name,), {})
     103                                     (expression,), {})
    104104        else:
    105             entity = self.get_entity(name)
     105            entity = self.get_entity(expression)
    106106            return get_arg_text(entity)
    107107
    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:
    111113            namespace = sys.modules.copy()
    112114            namespace.update(__main__.__dict__)
    113115            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.
    116120                return None
    117121
     
    128132
    129133def 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."""
    131136    arg_text = ""
    132     if ob is not None:
     137    if ob is not None and hasattr(ob, '__call__'):
    133138        arg_offset = 0
    134139        if type(ob) in (types.ClassType, types.TypeType):
     
    159164                items.append("***")
    160165            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)
    162167        # See if we can use the docstring
    163168        doc = getattr(ob, "__doc__", "")
     
    219224             TC, tc.t1, tc.t2, tc.t3, tc.t4, tc.t5, tc.t6, tc.t7)
    220225
    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.