repl.py 文件源码

python
阅读 27 收藏 0 点赞 0 评论 0

项目:PyAcid 作者: Acid-ZdS 项目源码 文件源码
def _get_command_desc(name):
    try:
        fn = REPL.get_command(name)
    except KeyError:
        print('Error: command {!r} is not defined.'.format(name))

    if fn.__doc__ is not None:
        doc = fn.__doc__.strip()
    else:
        doc = 'No documentation available for this command'

    arg_desc = ''
    sig = inspect.signature(fn)

    # ignore the self parameter
    for pname, param in list(sig.parameters.items())[1:]:
        if param.kind == inspect.Parameter.POSITIONAL_OR_KEYWORD:
            if param.default == inspect._empty:
                arg_desc += '<{}> '.format(pname)
            elif param.default is None:
                arg_desc += '[{}] '.format(pname)
            else:
                arg_desc += '[{}={!r}] '.format(pname, param.default)
        elif param.kind == inspect.Parameter.POSITIONAL_ONLY:
            arg_desc += '[{} ...] '.format(pname)
        else:
            # dirty :(
            pass

    desc = ':{name} {args}'.format(
        name=name,
        args=arg_desc
    )
    return '{desc:<30}\t\t{doc}'.format(
        desc=desc,
        doc=doc
    )
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号