您好, 欢迎来到 !    登录 | 注册 | | 设为首页 | 收藏本站

在Sphinx文档中保留包装/装饰的Python函数的默认参数

在Sphinx文档中保留包装/装饰的Python函数的默认参数

我想出了一个猴子补丁functools.wraps。因此,我只是将其添加到了conf.py项目文档的sphinxsource文件夹中的脚本中:

# Monkey-patch functools.wraps
import functools

def no_op_wraps(func):
    """Replaces functools.wraps in order to undo wrapping.

    Can be used to preserve the decorated function's signature
    in the documentation generated by Sphinx.

    """
    def wrapper(decorator):
        return func
    return wrapper

functools.wraps = no_op_wraps

因此,当通过构建html页面make htmlfunctools.wraps此装饰器no_op_wraps将替换它,该装饰器仅返回原始函数就什么也不做。

python 2022/1/1 18:48:39 有356人围观

撰写回答


你尚未登录,登录后可以

和开发者交流问题的细节

关注并接收问题和回答的更新提醒

参与内容的编辑和改进,让解决方法与时俱进

请先登录

推荐问题


联系我
置顶