Skip to content

Commit 43ba022

Browse files
committed
add good-dunder-names option
1 parent 37ca3dd commit 43ba022

File tree

5 files changed

+23
-3
lines changed

5 files changed

+23
-3
lines changed

pylint/extensions/dunder.py

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
from astroid import nodes
1010

1111
from pylint.checkers import BaseChecker
12-
from pylint.constants import DUNDER_METHODS, EXTRA_DUNDER_METHODS, DUNDER_PROPERTIES
12+
from pylint.constants import DUNDER_METHODS, DUNDER_PROPERTIES, EXTRA_DUNDER_METHODS
1313
from pylint.interfaces import HIGH
1414

1515
if TYPE_CHECKING:
@@ -29,10 +29,24 @@ class DunderChecker(BaseChecker):
2929
"not within the predefined list of dunder names.",
3030
),
3131
}
32-
options = ()
32+
options = (
33+
(
34+
"good-dunder-names",
35+
{
36+
"default": [],
37+
"type": "csv",
38+
"metavar": "<comma-separated names>",
39+
"help": "Good dunder names which should always be accepted.",
40+
},
41+
),
42+
)
3343

3444
def open(self) -> None:
35-
self._dunder_methods = EXTRA_DUNDER_METHODS + DUNDER_PROPERTIES
45+
self._dunder_methods = (
46+
EXTRA_DUNDER_METHODS
47+
+ DUNDER_PROPERTIES
48+
+ self.linter.config.good_dunder_names
49+
)
3650
for since_vers, dunder_methods in DUNDER_METHODS.items():
3751
if since_vers <= self.linter.config.py_version:
3852
self._dunder_methods.extend(list(dunder_methods.keys()))

tests/__init__.py

Whitespace-only changes.

tests/functional/ext/__init__.py

Whitespace-only changes.

tests/functional/ext/bad_dunder/bad_dunder_name.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,10 @@ def __inv__(self): # [bad-dunder-name]
3535
# author likely meant to call the invert dunder method
3636
pass
3737

38+
def __allowed__(self):
39+
# user-configured allowed dunder name
40+
pass
41+
3842
def _protected_method(self):
3943
print("Protected")
4044

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,4 @@
11
[MAIN]
22
load-plugins=pylint.extensions.dunder
3+
4+
good-dunder-names = __allowed__,

0 commit comments

Comments
 (0)