【发布时间】:2019-12-20 21:28:20
【问题描述】:
例如我有简单的功能:
def foo(a):
'''
Some function.
a : int
'''
print(a+10)
它按我的预期工作 - 当我将鼠标放在该功能上时,我可以看到有用的帮助:
但如果我使用包装器,有关函数参数的有用信息就会丢失:
def simple_decorator(f):
def inner(*args, **kwargs):
'''
Simple decorator
'''
res = f(*args, **kwargs)
print('Wrapped')
return res
return inner
@simple_decorator
def foo(a):
'''
Some function.
a : int
'''
print(a+10)
但是!我可以使用 Ctrl + 鼠标悬停功能查看信息:
这种方式仍然无法帮助显示函数的参数 - 当我添加括号时,我再次只看到*args, **kwargs。
我也试过from functools import wraps 也不行。
是否可以让智能正常工作,显示包装函数的参数?或者可能总是同时显示它们,就像在 Ctrl+Mouse 上一样?
附:我在 GitHub 上发现了很多已关闭的问题,但仍然无法弄清楚如何解决它。例如: https://github.com/davidhalter/jedi/issues/906
【问题讨论】:
-
我无法使用 VSC 1.37 和最新的 ms-python 扩展进行复制。也不适用于 Python 2.7 或 Python 3.6。无论有没有装饰器,我都会得到相同的提示。
-
@rioV8 我使用 VS Code 1.37.0 和 Python 扩展 2019.8.30787。并尝试了一切。我也试过禁用绝地。还是同样的问题。请出示您的代码好吗?
-
他们一定是最近更新了,因为我使用的是 ms-python 2019.8.29288
-
@rioV8 我试过 29288 但仍然有同样的错误。你能显示你的代码吗?你用
@wraps吗? -
我只是用装饰器复制/粘贴你的源代码
标签: python python-3.x visual-studio-code wrapper vscode-settings