Skip to content

Commit

Permalink
Fix Enum invalid name with snake_case preset
Browse files Browse the repository at this point in the history
  • Loading branch information
cdce8p authored and Pierre-Sassoulas committed Mar 2, 2021
1 parent 15396a1 commit 25e63b0
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 5 deletions.
8 changes: 7 additions & 1 deletion ChangeLog
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ Release date: TBA
..
Put new features here

* Workflow and packaging improvements

What's New in Pylint 2.7.3?
===========================
Expand All @@ -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?
===========================
Expand All @@ -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
Expand Down
3 changes: 2 additions & 1 deletion pylint/checkers/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 <arg>"""
Expand Down
7 changes: 7 additions & 0 deletions tests/functional/n/name_preset_snake_case.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
# pylint: disable=missing-docstring,too-few-public-methods
from enum import Enum

__version__ = "1.0"
SOME_CONSTANT = 42 # [invalid-name]

Expand All @@ -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
7 changes: 4 additions & 3 deletions tests/functional/n/name_preset_snake_case.txt
Original file line number Diff line number Diff line change
@@ -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)"

0 comments on commit 25e63b0

Please sign in to comment.