Example #1
0
def annotated_signature(func,
                        argspec=None,
                        slf_or_clsm=False,
                        assumed_globals=None):
    # inspect.formatargspec would only work in Python 3 with annotations
    if argspec is None:
        argspec = util.getargspecs(func)
    _types = type_util.get_types(func)
    sig_lst = []
    tp_lst = typelogger._prepare_arg_types_list(_types[0], argspec,
                                                slf_or_clsm, sig_lst)
    for i in range(len(sig_lst)):
        sig_lst[i] += ': ' + type_util.type_str(tp_lst[i], assumed_globals,
                                                True, _implicit_globals)
    if slf_or_clsm:
        sig_lst.insert(0, argspec.args[0])
    res_tp = type_util.type_str(_types[1], assumed_globals, True,
                                _implicit_globals)
    res = ''.join(('(', ', '.join(sig_lst), ') -> ', res_tp))
    return ''.join(('def ', func.__name__, res.replace('NoneType',
                                                       'None'), ':'))
Example #2
0
def signature(func):
    argstr = ', '.join(util.getargnames(util.getargspecs(func), True))
    return 'def ' + func.__name__ + '(' + argstr + '):'
Example #3
0
def typecomment(func, argspec=None, slf_or_clsm=False, assumed_globals=None):
    if argspec is None:
        argspec = util.getargspecs(func)
    return _typecomment(type_util.get_types(func), argspec, slf_or_clsm,
                        assumed_globals)