Skip to content

Commit 48e6585

Browse files
committed
Use argparse config handler on three checkers
1 parent 828a0d9 commit 48e6585

File tree

3 files changed

+27
-20
lines changed

3 files changed

+27
-20
lines changed

pylint/checkers/base/docstring_checker.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -115,12 +115,12 @@ def visit_module(self, node: nodes.Module) -> None:
115115

116116
@utils.check_messages("missing-docstring", "empty-docstring")
117117
def visit_classdef(self, node: nodes.ClassDef) -> None:
118-
if self.config.no_docstring_rgx.match(node.name) is None:
118+
if self.linter.namespace.no_docstring_rgx.match(node.name) is None:
119119
self._check_docstring("class", node)
120120

121121
@utils.check_messages("missing-docstring", "empty-docstring")
122122
def visit_functiondef(self, node: nodes.FunctionDef) -> None:
123-
if self.config.no_docstring_rgx.match(node.name) is None:
123+
if self.linter.namespace.no_docstring_rgx.match(node.name) is None:
124124
ftype = "method" if node.is_method() else "function"
125125
if (
126126
is_property_setter(node)
@@ -176,7 +176,7 @@ def _check_docstring(
176176
# If the module does not have a body, there's no reason
177177
# to require a docstring.
178178
return
179-
max_lines = self.config.docstring_min_length
179+
max_lines = self.linter.namespace.docstring_min_length
180180

181181
if node_type != "module" and max_lines > -1 and lines < max_lines:
182182
return

pylint/checkers/refactoring/refactoring_checker.py

+8-5
Original file line numberDiff line numberDiff line change
@@ -461,6 +461,7 @@ class RefactoringChecker(checkers.BaseTokenChecker):
461461
{
462462
"default": ("sys.exit", "argparse.parse_error"),
463463
"type": "csv",
464+
"metavar": "<members names>",
464465
"help": "Complete name of functions that never returns. When checking "
465466
"for inconsistent-return-statements if a never returning function is "
466467
"called then it will be considered as an explicit return statement "
@@ -469,8 +470,8 @@ class RefactoringChecker(checkers.BaseTokenChecker):
469470
),
470471
)
471472

472-
def __init__(self, linter=None):
473-
super().__init__(linter)
473+
def __init__(self, linter):
474+
super().__init__(linter, future_option_parsing=True)
474475
self._return_nodes = {}
475476
self._consider_using_with_stack = ConsiderUsingWithStack()
476477
self._init()
@@ -486,7 +487,9 @@ def _init(self):
486487

487488
def open(self):
488489
# do this in open since config not fully initialized in __init__
489-
self._never_returning_functions = set(self.config.never_returning_functions)
490+
self._never_returning_functions = set(
491+
self.linter.namespace.never_returning_functions
492+
)
490493

491494
@cached_property
492495
def _dummy_rgx(self):
@@ -1125,11 +1128,11 @@ def _check_nested_blocks(self, node):
11251128
self._emit_nested_blocks_message_if_needed(nested_blocks)
11261129

11271130
def _emit_nested_blocks_message_if_needed(self, nested_blocks):
1128-
if len(nested_blocks) > self.config.max_nested_blocks:
1131+
if len(nested_blocks) > self.linter.namespace.max_nested_blocks:
11291132
self.add_message(
11301133
"too-many-nested-blocks",
11311134
node=nested_blocks[0],
1132-
args=(len(nested_blocks), self.config.max_nested_blocks),
1135+
args=(len(nested_blocks), self.linter.namespace.max_nested_blocks),
11331136
)
11341137

11351138
def _emit_consider_using_with_if_needed(self, stack: Dict[str, nodes.NodeNG]):

pylint/checkers/spelling.py

+16-12
Original file line numberDiff line numberDiff line change
@@ -263,44 +263,48 @@ class SpellingChecker(BaseTokenChecker):
263263
),
264264
)
265265

266+
def __init__(self, linter: "PyLinter") -> None:
267+
super().__init__(linter, future_option_parsing=True)
268+
266269
def open(self):
267270
self.initialized = False
268271
self.private_dict_file = None
269272

270273
if enchant is None:
271274
return
272-
dict_name = self.config.spelling_dict
275+
dict_name = self.linter.namespace.spelling_dict
273276
if not dict_name:
274277
return
275278

276279
self.ignore_list = [
277-
w.strip() for w in self.config.spelling_ignore_words.split(",")
280+
w.strip() for w in self.linter.namespace.spelling_ignore_words.split(",")
278281
]
279282
# "param" appears in docstring in param description and
280283
# "pylint" appears in comments in pylint pragmas.
281284
self.ignore_list.extend(["param", "pylint"])
282285

283286
self.ignore_comment_directive_list = [
284-
w.strip() for w in self.config.spelling_ignore_comment_directives.split(",")
287+
w.strip()
288+
for w in self.linter.namespace.spelling_ignore_comment_directives.split(",")
285289
]
286290

287291
# Expand tilde to allow e.g. spelling-private-dict-file = ~/.pylintdict
288-
if self.config.spelling_private_dict_file:
289-
self.config.spelling_private_dict_file = os.path.expanduser(
290-
self.config.spelling_private_dict_file
292+
if self.linter.namespace.spelling_private_dict_file:
293+
self.linter.namespace.spelling_private_dict_file = os.path.expanduser(
294+
self.linter.namespace.spelling_private_dict_file
291295
)
292296

293-
if self.config.spelling_private_dict_file:
297+
if self.linter.namespace.spelling_private_dict_file:
294298
self.spelling_dict = enchant.DictWithPWL(
295-
dict_name, self.config.spelling_private_dict_file
299+
dict_name, self.linter.namespace.spelling_private_dict_file
296300
)
297301
self.private_dict_file = open( # pylint: disable=consider-using-with
298-
self.config.spelling_private_dict_file, "a", encoding="utf-8"
302+
self.linter.namespace.spelling_private_dict_file, "a", encoding="utf-8"
299303
)
300304
else:
301305
self.spelling_dict = enchant.Dict(dict_name)
302306

303-
if self.config.spelling_store_unknown_words:
307+
if self.linter.namespace.spelling_store_unknown_words:
304308
self.unknown_words = set()
305309

306310
self.tokenizer = get_tokenizer(
@@ -374,14 +378,14 @@ def _check_spelling(self, msgid, line, line_num):
374378
continue
375379

376380
# Store word to private dict or raise a message.
377-
if self.config.spelling_store_unknown_words:
381+
if self.linter.namespace.spelling_store_unknown_words:
378382
if lower_cased_word not in self.unknown_words:
379383
self.private_dict_file.write(f"{lower_cased_word}\n")
380384
self.unknown_words.add(lower_cased_word)
381385
else:
382386
# Present up to N suggestions.
383387
suggestions = self.spelling_dict.suggest(word)
384-
del suggestions[self.config.max_spelling_suggestions :]
388+
del suggestions[self.linter.namespace.max_spelling_suggestions :]
385389
line_segment = line[word_start_at:]
386390
match = re.search(rf"(\W|^)({word})(\W|$)", line_segment)
387391
if match:

0 commit comments

Comments
 (0)