Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/python-3.x/18.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/extjs/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 包装函数时记录函数参数_Python_Python 3.x_Pycharm_Wrapper_Type Hinting - Fatal编程技术网

Python 包装函数时记录函数参数

Python 包装函数时记录函数参数,python,python-3.x,pycharm,wrapper,type-hinting,Python,Python 3.x,Pycharm,Wrapper,Type Hinting,我已经编写了一些代码来像这样包装shutil.copy文件(这是一个大大简化的示例): 在PyCharm中,如果我键入mycopyfile.它建议*args和**kwargs作为参数。我如何才能使它如此PyCharm,以及其他IDE建议shutil.copyfile的参数 此外,PyCharm中的快速文档使用mycopyfile的文档,而不是docs shutil.copy文件,即使mycopyfile。doc正确返回文档(由@wraps decorator确定)在这种情况下,静态分析如何建议s

我已经编写了一些代码来像这样包装shutil.copy文件(这是一个大大简化的示例):

在PyCharm中,如果我键入mycopyfile.它建议*args和**kwargs作为参数。我如何才能使它如此PyCharm,以及其他IDE建议shutil.copyfile的参数


此外,PyCharm中的快速文档使用mycopyfile的文档,而不是docs shutil.copy文件,即使mycopyfile。doc正确返回文档(由@wraps decorator确定)

在这种情况下,静态分析如何建议
shutil.copyfile
的参数并不明显。在Python级别,您可以通过执行以下操作来伪造它:
wrapper.\uuu签名\uuu=signature(copyfile)
。其中签名来自检查导入签名“”。
from functools import wraps
from shutil import copyfile


def my_wrapper(f):
    @wraps(f)
    def wrapper(*args, **kwargs):
        return f(*args, **kwargs)

    return wrapper


@my_wrapper
def mycopyfile(*args, **kwargs):
    """Wrap :func:`shutil.copyfile`"""
    return copyfile(*args, **kwargs)