Skip to content

Commit cb9dc79

Browse files
authored
Re-use regex pattern in naming style (#6072)
1 parent bb84699 commit cb9dc79

1 file changed

Lines changed: 4 additions & 10 deletions

File tree

pylint/checkers/base/name_checker/naming_style.py

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,9 @@ def get_regex(cls, name_type):
4141
class SnakeCaseStyle(NamingStyle):
4242
"""Regex rules for snake_case naming style."""
4343

44-
CLASS_NAME_RGX = re.compile(r"[^\W\dA-Z][^\WA-Z]+$")
44+
CLASS_NAME_RGX = COMP_VAR_RGX = re.compile(r"[^\W\dA-Z][^\WA-Z]+$")
4545
MOD_NAME_RGX = re.compile(r"[^\W\dA-Z][^\WA-Z]*$")
4646
CONST_NAME_RGX = re.compile(r"([^\W\dA-Z][^\WA-Z]*|__.*__)$")
47-
COMP_VAR_RGX = re.compile(r"[^\W\dA-Z][^\WA-Z]*$")
4847
DEFAULT_NAME_RGX = re.compile(
4948
r"([^\W\dA-Z][^\WA-Z]{2,}|_[^\WA-Z]*|__[^\WA-Z\d_][^\WA-Z]+__)$"
5049
)
@@ -55,31 +54,26 @@ class CamelCaseStyle(NamingStyle):
5554
"""Regex rules for camelCase naming style."""
5655

5756
CLASS_NAME_RGX = re.compile(r"[^\W\dA-Z][^\W_]+$")
58-
MOD_NAME_RGX = re.compile(r"[^\W\dA-Z][^\W_]*$")
57+
MOD_NAME_RGX = COMP_VAR_RGX = re.compile(r"[^\W\dA-Z][^\W_]*$")
5958
CONST_NAME_RGX = re.compile(r"([^\W\dA-Z][^\W_]*|__.*__)$")
60-
COMP_VAR_RGX = re.compile(r"[^\W\dA-Z][^\W_]*$")
6159
DEFAULT_NAME_RGX = re.compile(r"([^\W\dA-Z][^\W_]{2,}|__[^\W\dA-Z_]\w+__)$")
6260
CLASS_ATTRIBUTE_RGX = re.compile(r"([^\W\dA-Z][^\W_]{2,}|__.*__)$")
6361

6462

6563
class PascalCaseStyle(NamingStyle):
6664
"""Regex rules for PascalCase naming style."""
6765

68-
CLASS_NAME_RGX = re.compile(r"[^\W\da-z][^\W_]+$")
69-
MOD_NAME_RGX = re.compile(r"[^\W\da-z][^\W_]+$")
66+
CLASS_NAME_RGX = MOD_NAME_RGX = COMP_VAR_RGX = re.compile(r"[^\W\da-z][^\W_]+$")
7067
CONST_NAME_RGX = re.compile(r"([^\W\da-z][^\W_]*|__.*__)$")
71-
COMP_VAR_RGX = re.compile(r"[^\W\da-z][^\W_]+$")
7268
DEFAULT_NAME_RGX = re.compile(r"([^\W\da-z][^\W_]{2,}|__[^\W\dA-Z_]\w+__)$")
7369
CLASS_ATTRIBUTE_RGX = re.compile(r"[^\W\da-z][^\W_]{2,}$")
7470

7571

7672
class UpperCaseStyle(NamingStyle):
7773
"""Regex rules for UPPER_CASE naming style."""
7874

79-
CLASS_NAME_RGX = re.compile(r"[^\W\da-z][^\Wa-z]+$")
80-
MOD_NAME_RGX = re.compile(r"[^\W\da-z][^\Wa-z]+$")
75+
CLASS_NAME_RGX = MOD_NAME_RGX = COMP_VAR_RGX = re.compile(r"[^\W\da-z][^\Wa-z]+$")
8176
CONST_NAME_RGX = re.compile(r"([^\W\da-z][^\Wa-z]*|__.*__)$")
82-
COMP_VAR_RGX = re.compile(r"[^\W\da-z][^\Wa-z]+$")
8377
DEFAULT_NAME_RGX = re.compile(r"([^\W\da-z][^\Wa-z]{2,}|__[^\W\dA-Z_]\w+__)$")
8478
CLASS_ATTRIBUTE_RGX = re.compile(r"[^\W\da-z][^\Wa-z]{2,}$")
8579

0 commit comments

Comments
 (0)