有没有办法为带有 **kwargs 的函数提供签名参考(例如,对于 IDE)?
例如:
def foo(**kwargs):
# call some third-party library with kwargs signature
Run Code Online (Sandbox Code Playgroud)
我想为最新的 IDE 提供自动完成功能
那么,我如何在Python中描述签名
这并不完全是您想要的,但它可能help......
from other_package import my_function
def wrapped_help_text(wrapped_func):
"""Decorator to pass through the documentation from a wrapped function.
"""
def decorator(wrapper_func):
"""The decorator.
Parameters
----------
wrapped_func : callable
The wrapped function.
"""
wrapper_func.__doc__ = ('This method wraps the following method:\n\n' +
pydoc.text.document(wrapped_func))
return wrapper_func
return decorator
@wrapped_help_text(my_function)
def wrapper(**kwargs):
"""
Parameters
----------
**kwargs
See other_package.my_function()
"""
my_function(**kwargs)
Run Code Online (Sandbox Code Playgroud)
现在,您可以调用内置help函数来查看包装函数的文档字符串。