File tree Expand file tree Collapse file tree 3 files changed +23
-3
lines changed
tests/functional/ext/bad_dunder Expand file tree Collapse file tree 3 files changed +23
-3
lines changed Original file line number Diff line number Diff line change 99from astroid import nodes
1010
1111from 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
1313from pylint .interfaces import HIGH
1414
1515if 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 ()))
Original file line number Diff line number Diff 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
Original file line number Diff line number Diff line change 11[MAIN]
22load-plugins=pylint.extensions.dunder
3+
4+ good-dunder-names = __allowed__,
You can’t perform that action at this time.
0 commit comments