From 25e63b0606721e2cd07d4c2b3d88fcb0461b6db9 Mon Sep 17 00:00:00 2001 From: Marc Mueller <30130371+cdce8p@users.noreply.github.com> Date: Mon, 1 Mar 2021 03:26:11 +0100 Subject: [PATCH] Fix Enum invalid name with snake_case preset --- ChangeLog | 8 +++++++- pylint/checkers/base.py | 3 ++- tests/functional/n/name_preset_snake_case.py | 7 +++++++ tests/functional/n/name_preset_snake_case.txt | 7 ++++--- 4 files changed, 20 insertions(+), 5 deletions(-) diff --git a/ChangeLog b/ChangeLog index 3fe0f3cf64..5ba13b7755 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 373e0b20ac..384abb4714 100644 --- a/pylint/checkers/base.py +++ b/pylint/checkers/base.py @@ -1986,7 +1986,8 @@ def visit_assignname(self, node): 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 """ diff --git a/tests/functional/n/name_preset_snake_case.py b/tests/functional/n/name_preset_snake_case.py index 5498887153..892d340814 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 @@ def __eq__(self, other): 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 2fa1ae35e3..ffcdd9a664 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)"