【问题标题】:VS code shows pylint import errors while 'go to definition' worksVS 代码显示 pylint 导入错误,而“转到定义”工作
【发布时间】:2020-09-28 18:36:48
【问题描述】:

我有一个项目结构:

common (folder)
  |- __init__.py
  |- model.py
  |- monitoring.py
     |- class MyLogger

在 model.py 文件中,我有这一行和以下错误: from common.monitoring import MyLogger

错误:

No name 'monitoring ' in module 'common'    pylint (no-name-in-module).
Unable to import 'common.monitoring'    pylint(import-error).

import monitoring 遇到同样的错误。

在实践中:

  1. 代码运行流畅
  2. F12(转到定义)工作并进入 MyLogger。

我在网上搜索并找不到如何很好地配置 VS 代码来消除这些错误。

【问题讨论】:

  • “转到定义”与 linter 无关,顺便说一句。您是否已将 pylint 安装到与该项目相关的 python 环境中?
  • 我已经安装并运行了 pylint。我按照这个方向安装了 Bandit(列表中的第一个 linting 工具)——似乎清除了所有这些导入错误。你知道为什么吗?我可以将 pylint 配置为更好地工作还是继续使用 Bandit?

标签: python python-3.x visual-studio-code vscode-settings pylint


【解决方案1】:

所以我最终找到了答案: How do I disable pylint unused import error messages in vs code

底线: 添加到settings.json:

"python.linting.pylintArgs": [
        "--max-line-length=100",
        "--disable=W0142,W0403,W0613,W0232,R0903,R0913,C0103,R0914,C0304,F0401,W0402,E1101,W0614,C0111,C0301"
    ],

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-10-22
    • 2021-01-11
    • 2020-10-13
    • 1970-01-01
    • 2021-01-21
    • 2019-11-09
    • 2020-04-07
    • 2022-10-05
    相关资源
    最近更新 更多