这是一个类似的情况我已经遇到过了几个月前使用pylint的事先pylance:
我的python 3.9x- 脚本(使用VS Codeon Ubuntu 20.04 LTS)从以下自定义“工具”导入开始:
import sys
sys.path.append(
'/home/andylu/Dokumente/Allgemeines_material/Sonstiges/Programming/Python/Scripts/'
)
import General.Misc.general_tools as tools
Run Code Online (Sandbox Code Playgroud)
现在,Pylance声明:
Import "General.Misc.general_tools" could not be resolvedPylance (reportMissingImports)
Run Code Online (Sandbox Code Playgroud)
即使在程序执行期间模块被完美地导入,也会发生这种情况。
因此,为了确保Pylance理解这是一个现有的模块路径,除了sys.path.append(..)- 方法之外,我在settings.json- 文件中添加了以下内容:
{
...
// Possible values: "Jedi", "Pylance", "Microsoft", "None".
"python.languageServer": "Pylance",
// NOTE on changing from microsoft to pylance language server: python.autoComplete.extraPaths --> python.analysis.extraPaths
// Docs: https://github.com/microsoft/pylance-release/blob/master/TROUBLESHOOTING.md#unresolved-import-warnings
"python.analysis.extraPaths": [
"/home/andylu/Dokumente/Allgemeines_material/Sonstiges/Programming/Python/Scripts"
],
... …Run Code Online (Sandbox Code Playgroud) python-import python-3.x visual-studio-code vscode-settings pylance
直到大约 3 周前,我一直在使用pylintpython来检查VS Code.
然后,我启用了pylance替换pylint. 然而,pylance并未在提供的特定 linter-listVS Code中列出。
现在,pylance 不显示未使用的模块导入。我怀疑这不包含在 的默认 linting 参数中pylance,因此我尝试找出如何修改它们,类似于使用 执行此操作的过程pylint,例如此处记录并像这样实现(插入到settings.json当前工作区的 - 文件中) ):
"python.linting.pylintArgs": [
"--max-line-length=80",
"--disable=W0142,W0403,W0613,W0232,R0903,R0913,C0103,R0914,C0304,F0401,W0402,E1101,W0614,C0111,C0301"
]
Run Code Online (Sandbox Code Playgroud)
我如何以类似的方式自定义 的 linting 规则pylance?