Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

False positive: invalid-name for UPPER_CASE Enum values #4149

Closed
iFreilicht opened this issue Feb 26, 2021 · 5 comments · Fixed by #4162
Closed

False positive: invalid-name for UPPER_CASE Enum values #4149

iFreilicht opened this issue Feb 26, 2021 · 5 comments · Fixed by #4162
Labels
Bug 🪲 Configuration Related to configuration

Comments

@iFreilicht
Copy link

iFreilicht commented Feb 26, 2021

Steps to reproduce

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.

Current behavior

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)

Expected behavior

I would expect this to not return any errors.

pylint --version output

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]
@jamesbraza
Copy link

jamesbraza commented Feb 26, 2021

+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)]

@cdce8p
Copy link
Member

cdce8p commented Feb 27, 2021

@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.

@jamesbraza
Copy link

Okay @cdce8p I opened a new issue: #4154

Also, I also can't reproduce @iFreilicht 's bug (I just tried it as well).

@iFreilicht
Copy link
Author

iFreilicht commented Feb 28, 2021

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               

@cdce8p
Copy link
Member

cdce8p commented Mar 1, 2021

@iFreilicht Probably not necessary anymore. I've opened a MR to address it: #4162

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug 🪲 Configuration Related to configuration
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants