【发布时间】:2021-01-02 02:30:37
【问题描述】:
在 VS Code 中,使用 os.path.join 时,Problems 选项卡显示错误,但代码实际运行。我如何告诉 MyPy 这些不是错误?
我在Salome平台上工作,运行的现有代码显示以下错误:(具体程序是envSalome.py,它是启动整个salome-meca表演的程序):
import os
kernel_root=os.getenv("KERNEL_ROOT_DIR")
kernel_root = os.path.realpath(kernel_root) # this is line 39 in the error below
sys.path[:0]=[os.path.join(kernel_root,"bin","salome")] # this is line 40 in the error below
这个程序运行没有错误。
我使用 VS Code 左下角的 python 解释器链接选择了 Salome 附带的 python3.exe(并且运行此代码没有错误)。
我的问题:
在终端窗口的“问题”选项卡中,MyPy 显示以下错误:
“realpath”的类型变量“AnyStr”的值不能是“Optional[str]”mypy(error) [39, 16]
“加入”的参数 1 具有不兼容的类型“Optional[str]”;预期 "Union[str, _PathLike[str]]" mypy(error) [40,29]
【问题讨论】:
-
我找到了一个解决方法:在vs代码设置下,搜索“linting”并关闭所有linter,然后从Microsoft安装pylance,即使它没有在“linting”下列出,它也会执行linting " 设置:并且 pylance 似乎没有将这些非错误标记为错误(到目前为止)。
标签: python visual-studio-code mypy