diff options
-rw-r--r-- | ChangeLog | 8 | ||||
-rw-r--r-- | pylint/checkers/base.py | 3 | ||||
-rw-r--r-- | tests/functional/n/name_preset_snake_case.py | 7 | ||||
-rw-r--r-- | tests/functional/n/name_preset_snake_case.txt | 7 |
4 files changed, 20 insertions, 5 deletions
@@ -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)" |