Skip to content

Commit

Permalink
bad dunder can start with _ or __
Browse files Browse the repository at this point in the history
  • Loading branch information
clavedeluna committed Oct 18, 2022
1 parent 46d491b commit 3bd3f61
Show file tree
Hide file tree
Showing 6 changed files with 8 additions and 8 deletions.
6 changes: 2 additions & 4 deletions pylint/checkers/dunder_methods.py
Original file line number Diff line number Diff line change
Expand Up @@ -211,11 +211,9 @@ def visit_functiondef(self, node: nodes.FunctionDef) -> None:
if not node.is_method():
return

# Detect something that could be a bad dunder method
if (
# Detect something that could be a dunder method
# It must start with `__` to be private, but could end
# with `_` if there is a misspelling.
node.name.startswith("__")
node.name.startswith(("_", "__"))
and node.name.endswith("_")
and node.name not in self._dunder_methods
and node.name not in EXTRA_DUNDER_METHODS + DUNDER_PROPERTIES
Expand Down
1 change: 1 addition & 0 deletions tests/functional/a/arguments_differ_issue5371.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# pylint: disable=bad-dunder-name
"""https://github.com/PyCQA/pylint/issues/5371"""
from enum import Enum

Expand Down
4 changes: 2 additions & 2 deletions tests/functional/b/bad_dunder_name.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ def __init_(self): # [bad-dunder-name]
# author likely unintentionally misspelled the correct init dunder.
pass

def _init_(self):
# protected, not private
def _init_(self): # [bad-dunder-name]
# author likely unintentionally misspelled the correct init dunder.
pass

def ___neg__(self): # [bad-dunder-name]
Expand Down
1 change: 1 addition & 0 deletions tests/functional/b/bad_dunder_name.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
bad-dunder-name:8:4:8:17:Apples.__hello__:Bad or misspelled dunder method name __hello__.:HIGH
bad-dunder-name:22:4:22:15:Apples.__init_:Bad or misspelled dunder method name __init_.:HIGH
bad-dunder-name:26:4:26:14:Apples._init_:Bad or misspelled dunder method name _init_.:HIGH
bad-dunder-name:30:4:30:16:Apples.___neg__:Bad or misspelled dunder method name ___neg__.:HIGH
bad-dunder-name:34:4:34:15:Apples.__inv__:Bad or misspelled dunder method name __inv__.:HIGH
2 changes: 1 addition & 1 deletion tests/functional/p/protected_access_special_methods_off.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
inside special methods occur
"""
# pylint: disable=missing-class-docstring, invalid-name, unused-variable
# pylint: disable=too-few-public-methods
# pylint: disable=too-few-public-methods, bad-dunder-name


class Protected:
Expand Down
2 changes: 1 addition & 1 deletion tests/functional/p/protected_access_special_methods_on.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
inside special methods.
"""
# pylint: disable=missing-class-docstring, invalid-name, unused-variable
# pylint: disable=too-few-public-methods
# pylint: disable=too-few-public-methods, bad-dunder-name


class Protected:
Expand Down

0 comments on commit 3bd3f61

Please sign in to comment.