Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions doc/whatsnew/fragments/10189.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Fixed raising invalid-name when using camelCase for private methods with two leading underscores.

Closes #10189
2 changes: 1 addition & 1 deletion pylint/checkers/base/name_checker/naming_style.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ class CamelCaseStyle(NamingStyle):
MOD_NAME_RGX = re.compile(r"[^\W\dA-Z][^\W_]*$")
CONST_NAME_RGX = re.compile(r"([^\W\dA-Z][^\W_]*|__.*__)$")
COMP_VAR_RGX = MOD_NAME_RGX
DEFAULT_NAME_RGX = re.compile(r"([^\W\dA-Z][^\W_]*|__[^\W\dA-Z_]\w+__)$")
DEFAULT_NAME_RGX = re.compile(r"(?:__)?([^\W\dA-Z][^\W_]*|__[^\W\dA-Z_]\w+__)$")
CLASS_ATTRIBUTE_RGX = re.compile(r"([^\W\dA-Z][^\W_]*|__.*__)$")


Expand Down
7 changes: 6 additions & 1 deletion tests/functional/n/namePresetCamelCase.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# pylint: disable=missing-docstring,too-few-public-methods
# pylint: disable=missing-docstring,too-few-public-methods,unused-private-member
__version__ = "1.0"
SOME_CONSTANT = 42 # [invalid-name]

Expand All @@ -18,6 +18,11 @@ def myPublicX(self):
def __eq__(self, other):
return isinstance(other, MyClass) and self.myPublicX == other.myPublicX

def __privateMethod(self):
pass

def _protectedMethod(self):
pass

def say_hello(): # [invalid-name]
pass
6 changes: 3 additions & 3 deletions tests/functional/n/namePresetCamelCase.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
invalid-name:3:0:3:13::"Constant name ""SOME_CONSTANT"" doesn't conform to camelCase naming style ('([^\\W\\dA-Z][^\\W_]*|__.*__)$' pattern)":HIGH
invalid-name:10:0:10:13:MyClass:"Class name ""MyClass"" doesn't conform to camelCase naming style ('[^\\W\\dA-Z][^\\W_]*$' pattern)":HIGH
invalid-name:22:0:22:13:say_hello:"Function name ""say_hello"" doesn't conform to camelCase naming style ('([^\\W\\dA-Z][^\\W_]*|__[^\\W\\dA-Z_]\\w+__)$' pattern)":HIGH
invalid-name:3:0:3:13::"Constant name ""SOME_CONSTANT"" doesn't conform to camelCase naming style ('([^\\W\\dA-Z][^\\W_]*|__.*__)$' pattern)":HIGH
invalid-name:10:0:10:13:MyClass:"Class name ""MyClass"" doesn't conform to camelCase naming style ('[^\\W\\dA-Z][^\\W_]*$' pattern)":HIGH
invalid-name:27:0:27:13:say_hello:"Function name ""say_hello"" doesn't conform to camelCase naming style ('(?:__)?([^\\W\\dA-Z][^\\W_]*|__[^\\W\\dA-Z_]\\w+__)$' pattern)":HIGH
Loading