From cb9dc791a0e83f90391cc234b03cb5e4769400b3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dani=C3=ABl=20van=20Noord?= <13665637+DanielNoord@users.noreply.github.com> Date: Thu, 31 Mar 2022 15:04:48 +0200 Subject: [PATCH] Re-use regex pattern in naming style (#6072) --- pylint/checkers/base/name_checker/naming_style.py | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) diff --git a/pylint/checkers/base/name_checker/naming_style.py b/pylint/checkers/base/name_checker/naming_style.py index 98bdaf737b..9ef675ccc5 100644 --- a/pylint/checkers/base/name_checker/naming_style.py +++ b/pylint/checkers/base/name_checker/naming_style.py @@ -41,10 +41,9 @@ def get_regex(cls, name_type): class SnakeCaseStyle(NamingStyle): """Regex rules for snake_case naming style.""" - CLASS_NAME_RGX = re.compile(r"[^\W\dA-Z][^\WA-Z]+$") + CLASS_NAME_RGX = COMP_VAR_RGX = re.compile(r"[^\W\dA-Z][^\WA-Z]+$") MOD_NAME_RGX = re.compile(r"[^\W\dA-Z][^\WA-Z]*$") CONST_NAME_RGX = re.compile(r"([^\W\dA-Z][^\WA-Z]*|__.*__)$") - COMP_VAR_RGX = re.compile(r"[^\W\dA-Z][^\WA-Z]*$") DEFAULT_NAME_RGX = re.compile( r"([^\W\dA-Z][^\WA-Z]{2,}|_[^\WA-Z]*|__[^\WA-Z\d_][^\WA-Z]+__)$" ) @@ -55,9 +54,8 @@ class CamelCaseStyle(NamingStyle): """Regex rules for camelCase naming style.""" CLASS_NAME_RGX = re.compile(r"[^\W\dA-Z][^\W_]+$") - MOD_NAME_RGX = re.compile(r"[^\W\dA-Z][^\W_]*$") + MOD_NAME_RGX = COMP_VAR_RGX = re.compile(r"[^\W\dA-Z][^\W_]*$") CONST_NAME_RGX = re.compile(r"([^\W\dA-Z][^\W_]*|__.*__)$") - COMP_VAR_RGX = re.compile(r"[^\W\dA-Z][^\W_]*$") DEFAULT_NAME_RGX = re.compile(r"([^\W\dA-Z][^\W_]{2,}|__[^\W\dA-Z_]\w+__)$") CLASS_ATTRIBUTE_RGX = re.compile(r"([^\W\dA-Z][^\W_]{2,}|__.*__)$") @@ -65,10 +63,8 @@ class CamelCaseStyle(NamingStyle): class PascalCaseStyle(NamingStyle): """Regex rules for PascalCase naming style.""" - CLASS_NAME_RGX = re.compile(r"[^\W\da-z][^\W_]+$") - MOD_NAME_RGX = re.compile(r"[^\W\da-z][^\W_]+$") + CLASS_NAME_RGX = MOD_NAME_RGX = COMP_VAR_RGX = re.compile(r"[^\W\da-z][^\W_]+$") CONST_NAME_RGX = re.compile(r"([^\W\da-z][^\W_]*|__.*__)$") - COMP_VAR_RGX = re.compile(r"[^\W\da-z][^\W_]+$") DEFAULT_NAME_RGX = re.compile(r"([^\W\da-z][^\W_]{2,}|__[^\W\dA-Z_]\w+__)$") CLASS_ATTRIBUTE_RGX = re.compile(r"[^\W\da-z][^\W_]{2,}$") @@ -76,10 +72,8 @@ class PascalCaseStyle(NamingStyle): class UpperCaseStyle(NamingStyle): """Regex rules for UPPER_CASE naming style.""" - CLASS_NAME_RGX = re.compile(r"[^\W\da-z][^\Wa-z]+$") - MOD_NAME_RGX = re.compile(r"[^\W\da-z][^\Wa-z]+$") + CLASS_NAME_RGX = MOD_NAME_RGX = COMP_VAR_RGX = re.compile(r"[^\W\da-z][^\Wa-z]+$") CONST_NAME_RGX = re.compile(r"([^\W\da-z][^\Wa-z]*|__.*__)$") - COMP_VAR_RGX = re.compile(r"[^\W\da-z][^\Wa-z]+$") DEFAULT_NAME_RGX = re.compile(r"([^\W\da-z][^\Wa-z]{2,}|__[^\W\dA-Z_]\w+__)$") CLASS_ATTRIBUTE_RGX = re.compile(r"[^\W\da-z][^\Wa-z]{2,}$")