【问题标题】:Avoid Python lint warning for @dataclass variable declarations避免 @dataclass 变量声明的 Python lint 警告
【发布时间】:2019-05-21 15:18:13
【问题描述】:

我正在尝试 Python 3.7 中的 dataclasses 功能,但在单词“hue”下方收到此警告:

'hue' used before definition
Python (use-before-def)

我想这是一个 linter 警告。我尝试了几个 python 扩展提供的 linter,但它们都不起作用。

from dataclasses import dataclass
@dataclass
class Color:
    hue: int
    lightness: float = 2.0
c = Color(2)

有没有办法启用语法检查等但避免收到此警告?

使用 pep8 发出警告

使用 pylint 或 mypy 发出警告

【问题讨论】:

  • 您能否提供导致此错误的各种工具的版本号?你确定它们都更新到最新版本了吗?
  • Python扩展版本为2018.12.1

标签: python python-3.x visual-studio-code python-dataclasses


【解决方案1】:

您可以设置"python.analysis.disabled": ["use-before-def"] 禁用检查(docs)。 reported 将此错误归类为问题。

【讨论】:

    猜你喜欢
    • 2017-06-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-04-29
    相关资源
    最近更新 更多