[pywin32-checkins] pywin32/Pythonwin/pywin/idle CallTips.py, 1.4, 1.5
OLD project page for the Python extensions for Windows
Brought to you by:
mhammond
From: Mark H. <mha...@us...> - 2009-01-05 11:06:32
|
Update of /cvsroot/pywin32/pywin32/Pythonwin/pywin/idle In directory ddv4jf1.ch3.sourceforge.com:/tmp/cvs-serv30645/Pythonwin/pywin/idle Modified Files: CallTips.py Log Message: use inspect module as aid to making py3k-friendly Index: CallTips.py =================================================================== RCS file: /cvsroot/pywin32/pywin32/Pythonwin/pywin/idle/CallTips.py,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** CallTips.py 27 Nov 2008 03:53:25 -0000 1.4 --- CallTips.py 5 Jan 2009 11:06:23 -0000 1.5 *************** *** 4,8 **** import string import sys ! import types class CallTips: --- 4,9 ---- import string import sys ! import inspect ! import traceback class CallTips: *************** *** 101,105 **** # constructor (ie, __init__() ) or None if we can't find one. try: ! return class_ob.__init__.im_func except AttributeError: for base in class_ob.__bases__: --- 102,109 ---- # constructor (ie, __init__() ) or None if we can't find one. try: ! if sys.version_info < (3,): ! return class_ob.__init__.im_func ! else: ! return class_ob.__init__.__func__ except AttributeError: for base in class_ob.__bases__: *************** *** 113,146 **** if ob is not None: argOffset = 0 ! if type(ob)==types.ClassType: # Look for the highest __init__ in the class chain. fob = _find_constructor(ob) if fob is None: fob = lambda: None - else: - argOffset = 1 - elif type(ob)==types.MethodType: - # bit of a hack for methods - turn it into a function - # but we drop the "self" param. - fob = ob.im_func - argOffset = 1 else: fob = ob ! # Try and build one for Python defined functions ! if type(fob) in [types.FunctionType, types.LambdaType]: try: ! realArgs = fob.func_code.co_varnames[argOffset:fob.func_code.co_argcount] ! defaults = fob.func_defaults or [] ! defaults = list(map(lambda name: "=%s" % name, defaults)) ! defaults = [""] * (len(realArgs)-len(defaults)) + defaults ! items = map(lambda arg, dflt: arg+dflt, realArgs, defaults) ! if fob.func_code.co_flags & 0x4: ! items.append("...") ! if fob.func_code.co_flags & 0x8: ! items.append("***") ! argText = ", ".join(items) ! argText = "(%s)" % argText except: ! pass # See if we can use the docstring if hasattr(ob, "__doc__"): --- 117,135 ---- if ob is not None: argOffset = 0 ! if inspect.isclass(ob): # Look for the highest __init__ in the class chain. fob = _find_constructor(ob) if fob is None: fob = lambda: None else: fob = ob ! if inspect.isfunction(fob) or inspect.ismethod(fob): try: ! # py3k has a 'getfullargspec' which can handle py3k specific things. ! arg_getter = getattr(inspect, "getfullargspec", inspect.getargspec) ! argText = inspect.formatargspec(*arg_getter(fob)) except: ! print "Failed to format the args" ! traceback.print_exc() # See if we can use the docstring if hasattr(ob, "__doc__"): *************** *** 167,184 **** def t1(): "()" def t2(a, b=None): "(a, b=None)" ! def t3(a, *args): "(a, ...)" ! def t4(*args): "(...)" ! def t5(a, *args): "(a, ...)" ! def t6(a, b=None, *args, **kw): "(a, b=None, ..., ***)" class TC: ! "(a=None, ...)" ! def __init__(self, a=None, *b): "(a=None, ...)" ! def t1(self): "()" ! def t2(self, a, b=None): "(a, b=None)" ! def t3(self, a, *args): "(a, ...)" ! def t4(self, *args): "(...)" ! def t5(self, a, *args): "(a, ...)" ! def t6(self, a, b=None, *args, **kw): "(a, b=None, ..., ***)" def test( tests ): --- 156,173 ---- def t1(): "()" def t2(a, b=None): "(a, b=None)" ! def t3(a, *args): "(a, *args)" ! def t4(*args): "(*args)" ! def t5(a, *args): "(a, *args)" ! def t6(a, b=None, *args, **kw): "(a, b=None, *args, **kw)" class TC: ! "(self, a=None, *b)" ! def __init__(self, a=None, *b): "(self, a=None, *b)" ! def t1(self): "(self)" ! def t2(self, a, b=None): "(self, a, b=None)" ! def t3(self, a, *args): "(self, a, *args)" ! def t4(self, *args): "(self, *args)" ! def t5(self, a, *args): "(self, a, *args)" ! def t6(self, a, b=None, *args, **kw): "(self, a, b=None, *args, **kw)" def test( tests ): *************** *** 196,197 **** --- 185,187 ---- test(tests) + |