summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarc Mueller <30130371+cdce8p@users.noreply.github.com>2021-03-01 03:26:11 +0100
committerPierre Sassoulas <pierre.sassoulas@gmail.com>2021-03-02 09:46:20 +0100
commit25e63b0606721e2cd07d4c2b3d88fcb0461b6db9 (patch)
tree404ab4ddd14e35e4f8f1af4d62538b5952473c30
parent15396a14bc8f977a00b5288356e79467653a2c3c (diff)
downloadpylint-git-25e63b0606721e2cd07d4c2b3d88fcb0461b6db9.tar.gz
Fix Enum invalid name with snake_case preset
-rw-r--r--ChangeLog8
-rw-r--r--pylint/checkers/base.py3
-rw-r--r--tests/functional/n/name_preset_snake_case.py7
-rw-r--r--tests/functional/n/name_preset_snake_case.txt7
4 files changed, 20 insertions, 5 deletions
diff --git a/ChangeLog b/ChangeLog
index 3fe0f3cf6..5ba13b775 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -9,7 +9,6 @@ Release date: TBA
..
Put new features here
-* Workflow and packaging improvements
What's New in Pylint 2.7.3?
===========================
@@ -18,6 +17,10 @@ Release date: TBA
..
Put bug fixes that will be cherry-picked to latest major version here
+* Fix issue with Enums and `class-attribute-naming-style=snake_case`
+
+ Closes #4149
+
What's New in Pylint 2.7.2?
===========================
@@ -30,6 +33,9 @@ Release date: 2021-02-28
Closes #3636
+* Workflow and packaging improvements
+
+
What's New in Pylint 2.7.1?
===========================
Release date: 2021-02-23
diff --git a/pylint/checkers/base.py b/pylint/checkers/base.py
index 373e0b20a..384abb471 100644
--- a/pylint/checkers/base.py
+++ b/pylint/checkers/base.py
@@ -1986,7 +1986,8 @@ class NameChecker(_BasicChecker):
if ancestor.name == "Enum" and ancestor.root().name == "enum":
self._check_name("const", node.name, node)
break
- self._check_name("class_attribute", node.name, node)
+ else:
+ self._check_name("class_attribute", node.name, node)
def _recursive_check_names(self, args, node):
"""check names in a possibly recursive list <arg>"""
diff --git a/tests/functional/n/name_preset_snake_case.py b/tests/functional/n/name_preset_snake_case.py
index 549888715..892d34081 100644
--- a/tests/functional/n/name_preset_snake_case.py
+++ b/tests/functional/n/name_preset_snake_case.py
@@ -1,4 +1,6 @@
# pylint: disable=missing-docstring,too-few-public-methods
+from enum import Enum
+
__version__ = "1.0"
SOME_CONSTANT = 42 # [invalid-name]
@@ -21,3 +23,8 @@ class MyClass: # [invalid-name]
def sayHello(): # [invalid-name]
pass
+
+
+class FooEnum(Enum): # [invalid-name]
+ const_with_snake_case = 42
+ another_const = 43
diff --git a/tests/functional/n/name_preset_snake_case.txt b/tests/functional/n/name_preset_snake_case.txt
index 2fa1ae35e..ffcdd9a66 100644
--- a/tests/functional/n/name_preset_snake_case.txt
+++ b/tests/functional/n/name_preset_snake_case.txt
@@ -1,3 +1,4 @@
-invalid-name:3:0::"Constant name ""SOME_CONSTANT"" doesn't conform to snake_case naming style ('([^\\W\\dA-Z][^\\WA-Z]*|__.*__)$' pattern)"
-invalid-name:10:0:MyClass:"Class name ""MyClass"" doesn't conform to snake_case naming style ('[^\\W\\dA-Z][^\\WA-Z]+$' pattern)"
-invalid-name:22:0:sayHello:"Function name ""sayHello"" doesn't conform to snake_case naming style ('([^\\W\\dA-Z][^\\WA-Z]{2,}|_[^\\WA-Z]*|__[^\\WA-Z\\d_][^\\WA-Z]+__)$' pattern)"
+invalid-name:5:0::"Constant name ""SOME_CONSTANT"" doesn't conform to snake_case naming style ('([^\\W\\dA-Z][^\\WA-Z]*|__.*__)$' pattern)"
+invalid-name:12:0:MyClass:"Class name ""MyClass"" doesn't conform to snake_case naming style ('[^\\W\\dA-Z][^\\WA-Z]+$' pattern)"
+invalid-name:24:0:sayHello:"Function name ""sayHello"" doesn't conform to snake_case naming style ('([^\\W\\dA-Z][^\\WA-Z]{2,}|_[^\\WA-Z]*|__[^\\WA-Z\\d_][^\\WA-Z]+__)$' pattern)"
+invalid-name:28:0:FooEnum:"Class name ""FooEnum"" doesn't conform to snake_case naming style ('[^\\W\\dA-Z][^\\WA-Z]+$' pattern)"