问题描述
我有一个获取托管资源的函数:
I have a function as below to get managed resource:
from contextlib import contextmanager
@contextmanager
def getMyClass() -> MyClass:
...
obj = ...
try:
yield obj
...
except:
...
finally:
...
通过为 getMyClass 函数指定 Type,我想这个得到的对象可以在 with...as 语句中被识别,如下所示:
by specifying Type for the getMyClass function, I suppose this got object can be recognized in with...as statement as below:
with getMyClass() as obj:
obj.fun1()
但是,VSCode 无法识别 obj 的类型,并且不显示智能感知弹出菜单.有没有可能得到我需要的东西?
However, VSCode can't recognize the type of obj and the intellisense pop-up menu is not shown. Is it possible to get what I need?
PS:我也检查了 PyCharm,它也没有显示智能感知弹出菜单.
PS: I also check PyCharm, it doesn't show the intellisense pop-up menu either.
推荐答案
这在技术上取决于您使用的 IntelliSense 提供程序(Jedi 或语言服务器).对于后者,尚未实施.
This technically depends on which IntelliSense provider you're using (Jedi or the language server). In the case of the latter, it has not been implemented yet.
这篇关于VSCode 智能感知未在“with ... as"语句中为 Python 显示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!