Given a file a.py:
from enum import Enum
class System(Enum):
USER = 0
KERNEL = 1
Then run:
pylint --generate-rcfile > testrc
pylint --rcfile=testrc a.py
This is of course optional, I just did it to make sure my local .pylintrc wasn't the root of the problem.
Result of pylint --rcfile=testrc a.py:
************* Module a
a.py:4:4: C0103: Class attribute name "USER" doesn't conform to snake_case naming style (invalid-name)
a.py:5:4: C0103: Class attribute name "KERNEL" doesn't conform to snake_case naming style (invalid-name)
------------------------------------------------------------------
Your code has been rated at 5.00/10 (previous run: 5.00/10, +0.00)
But, changing the file so the names are snake_case will result in the opposite error:
tools/oracle/a.py:4:4: C0103: Constant name "user" doesn't conform to UPPER_CASE naming style (invalid-name)
tools/oracle/a.py:5:4: C0103: Constant name "kernel" doesn't conform to UPPER_CASE naming style (invalid-name)
I would expect this to not return any errors.
Result of pylint --version output:
pylint 2.7.1
astroid 2.5
Python 3.8.7 (default, Jan 11 2021, 15:36:11)
[GCC 10.2.0]
+1 on this one, but for dataclass
from dataclasses import dataclass
from typing import ClassVar
@dataclass
class Foo:
BAR: ClassVar[int] = 42
pylint path/to/show_bug.py
************* Module show_bug
path/to/show_bug.py:6:4: C0103: Attribute name "BAR" doesn't conform to snake_case naming style (invalid-name)
Output of pylint --version:
pylint 2.7.1
astroid 2.5
Python 3.7.9 (default, Oct 29 2020, 11:41:30)
[Clang 12.0.0 (clang-1200.0.32.27)]
@iFreilicht I might be missing something, but I can't reproduce the issue. It works as intended (no issues raised) for me.
pylint 2.7.1
astroid 2.5
Python 3.8.8 (v3.8.8:024d8058b0, Feb 19 2021, 08:48:17)
[Clang 6.0 (clang-600.0.57)]
@jamesbraza Please open a new issue for it, so we can track it properly. I would think the dataclass -> ClassVar logic hasn't been implemented yet.
Okay @cdce8p I opened a new issue: https://github.com/PyCQA/pylint/issues/4154
Also, I also can't reproduce @iFreilicht 's bug (I just tried it as well).
Ha, so the issue was indeed my .pylintrc. When running pylint --generate-rcfile > testrc, it generated testrc from my custom .pylintrc, so of course there wouldn't be a difference between them.
The real issue is; a value of class-attribute-naming-style=snake_case overrides the special case that Enum class attributes are considered constants. So I guess it's still a bug, but a different one than I thought.
Should I update the original issue description?
Here's a minimal .pylintrc to try it out with the a.py I posted above:
[BASIC]
class-attribute-naming-style=snake_case
[MESSAGES CONTROL]
disable=missing-docstring
@iFreilicht Probably not necessary anymore. I've opened a MR to address it: #4162