简体   繁体   English

如何摆脱 Visual Studio Code 中的一个智能感知警告

[英]How do I get rid of one intellisense warning in Visual Studio Code

在此处输入图像描述

I have the above directory structure in python and code works fine.我在 python 中有上述目录结构,代码工作正常。 But Visual Code thinks there is a problem.但是Visual Code认为有问题。 How do I disable this specific warning?如何禁用此特定警告?

While sys.path.insert() will probably work, it is a rather "hacky" solution.虽然 sys.path.insert() 可能会起作用,但它是一个相当“hacky”的解决方案。 And one reason for that is that a linter can't verify upfront, if the subsequent import will work: The sys.path will change at runtime only.一个原因是,如果后续导入有效,则 linter 无法预先验证: sys.path 只会在运行时更改。 This seems to be no problem for the author himself, but in case he needs to collaborate with other Python developers some day, they will most likely first check the linter report of his code before they pull it into their repository.这对作者本人来说似乎没有问题,但如果有一天他需要与其他 Python 开发人员合作,他们很可能会先检查他的代码的 linter 报告,然后再将其拉入他们的存储库。

" Clean coding " is different, but no magic at all. 干净的编码”是不同的,但根本没有魔法。 Use editable installs to make you package behave like in the target install:使用可编辑安装使 package 的行为类似于目标安装:

pip install -e mypackage

However, this requires a minimal setup.py in the mypackage root folder with但是,这需要 mypackage 根文件夹中的最小setup.py

import setuptools   
setuptools.setup(name='mypackage')

You could also try adding the no-quality-assistance (noqa) flag to the end of your import statement via您也可以尝试将no-quality-assistance (noqa) 标志添加到导入语句的末尾

import app_database as db  #noqa

but I would not recommend doing that.但我不建议这样做。

The intelligence analyser offers basic detection.情报分析仪提供基本检测。 So you can disable it by following settings因此,您可以通过以下设置禁用它

"python.analysis.disabled": [
    "use-before-def"
]

Doc:- https://code.visualstudio.com/docs/python/settings-reference#_python-language-server-settings文档:- https://code.visualstudio.com/docs/python/settings-reference#_python-language-server-settings

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM