Avoid Python lint warning for @dataclass variable declarations

Viewed 1041

I am having a try of the dataclasses feature in Python 3.7, but get this warning below word 'hue':

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

I suppose it is a linter warrning. I tried several linters that python extension provided, but none of them work.

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

Is there a way to have syntax checking etc enabled but avoid receiving this warning?

warning using pep8 warning and err

warning using pylint or mypy warning

1 Answers

You can set "python.analysis.disabled": ["use-before-def"] to disable the check (docs). The mis-classification of this as an issue has been reported.

Related