Back to index

python3.2  3.2.2
Classes | Functions
idlelib.CallTips Namespace Reference

Classes

class  CallTips

Functions

def _find_constructor
def get_argspec
def main
 Test code.

Detailed Description

CallTips.py - An IDLE Extension to Jog Your Memory

Call Tips are floating windows which display function, class, and method
parameter and docstring information when you type an opening parenthesis, and
which disappear when you type a closing parenthesis.

Function Documentation

def idlelib.CallTips._find_constructor (   class_ob) [private]

Definition at line 116 of file CallTips.py.

00116 
00117 def _find_constructor(class_ob):
00118     "Find the nearest __init__() in the class tree."
00119     try:
00120         return class_ob.__init__.__func__
00121     except AttributeError:
00122         for base in class_ob.__bases__:
00123             init = _find_constructor(base)
00124             if init:
00125                 return init
00126         return None

Here is the caller graph for this function:

Get a string describing the arguments for the given object.

Definition at line 127 of file CallTips.py.

00127 
00128 def get_argspec(ob):
00129     """Get a string describing the arguments for the given object."""
00130     argspec = ""
00131     if ob is not None:
00132         if isinstance(ob, type):
00133             fob = _find_constructor(ob)
00134             if fob is None:
00135                 fob = lambda: None
00136         elif isinstance(ob, types.MethodType):
00137             fob = ob.__func__
00138         else:
00139             fob = ob
00140         if isinstance(fob, (types.FunctionType, types.LambdaType)):
00141             argspec = inspect.formatargspec(*inspect.getfullargspec(fob))
00142             pat = re.compile('self\,?\s*')
00143             argspec = pat.sub("", argspec)
00144         doc = getattr(ob, "__doc__", "")
00145         if doc:
00146             doc = doc.lstrip()
00147             pos = doc.find("\n")
00148             if pos < 0 or pos > 70:
00149                 pos = 70
00150             if argspec:
00151                 argspec += "\n"
00152             argspec += doc[:pos]
00153     return argspec

Here is the call graph for this function:

Here is the caller graph for this function:

Test code.

Definition at line 158 of file CallTips.py.

00158 
00159 def main():
00160     def t1(): "()"
00161     def t2(a, b=None): "(a, b=None)"
00162     def t3(a, *args): "(a, *args)"
00163     def t4(*args): "(*args)"
00164     def t5(a, *args): "(a, *args)"
00165     def t6(a, b=None, *args, **kw): "(a, b=None, *args, **kw)"
00166 
00167     class TC(object):
00168         "(ai=None, *b)"
00169         def __init__(self, ai=None, *b): "(ai=None, *b)"
00170         def t1(self): "()"
00171         def t2(self, ai, b=None): "(ai, b=None)"
00172         def t3(self, ai, *args): "(ai, *args)"
00173         def t4(self, *args): "(*args)"
00174         def t5(self, ai, *args): "(ai, *args)"
00175         def t6(self, ai, b=None, *args, **kw): "(ai, b=None, *args, **kw)"
00176 
00177     __main__.__dict__.update(locals())
00178 
00179     def test(tests):
00180         ct = CallTips()
00181         failed=[]
00182         for t in tests:
00183             expected = t.__doc__ + "\n" + t.__doc__
00184             name = t.__name__
00185             # exercise fetch_tip(), not just get_argspec()
00186             try:
00187                 qualified_name = "%s.%s" % (t.__self__.__class__.__name__, name)
00188             except AttributeError:
00189                 qualified_name = name
00190             argspec = ct.fetch_tip(qualified_name)
00191             if argspec != expected:
00192                 failed.append(t)
00193                 fmt = "%s - expected %s, but got %s"
00194                 print(fmt % (t.__name__, expected, get_argspec(t)))
00195         print("%d of %d tests failed" % (len(failed), len(tests)))
00196 
00197     tc = TC()
00198     tests = (t1, t2, t3, t4, t5, t6,
00199              TC, tc.t1, tc.t2, tc.t3, tc.t4, tc.t5, tc.t6)
00200 
00201     test(tests)

Here is the call graph for this function: