diff --git a/pylint/checkers/base/docstring_checker.py b/pylint/checkers/base/docstring_checker.py index ab480ab58b..fd2d8a0aea 100644 --- a/pylint/checkers/base/docstring_checker.py +++ b/pylint/checkers/base/docstring_checker.py @@ -115,12 +115,12 @@ def visit_module(self, node: nodes.Module) -> None: @utils.check_messages("missing-docstring", "empty-docstring") def visit_classdef(self, node: nodes.ClassDef) -> None: - if self.config.no_docstring_rgx.match(node.name) is None: + if self.linter.namespace.no_docstring_rgx.match(node.name) is None: self._check_docstring("class", node) @utils.check_messages("missing-docstring", "empty-docstring") def visit_functiondef(self, node: nodes.FunctionDef) -> None: - if self.config.no_docstring_rgx.match(node.name) is None: + if self.linter.namespace.no_docstring_rgx.match(node.name) is None: ftype = "method" if node.is_method() else "function" if ( is_property_setter(node) @@ -176,7 +176,7 @@ def _check_docstring( # If the module does not have a body, there's no reason # to require a docstring. return - max_lines = self.config.docstring_min_length + max_lines = self.linter.namespace.docstring_min_length if node_type != "module" and max_lines > -1 and lines < max_lines: return diff --git a/pylint/checkers/refactoring/refactoring_checker.py b/pylint/checkers/refactoring/refactoring_checker.py index c9f78f68db..828fb7cdbb 100644 --- a/pylint/checkers/refactoring/refactoring_checker.py +++ b/pylint/checkers/refactoring/refactoring_checker.py @@ -461,6 +461,7 @@ class RefactoringChecker(checkers.BaseTokenChecker): { "default": ("sys.exit", "argparse.parse_error"), "type": "csv", + "metavar": "", "help": "Complete name of functions that never returns. When checking " "for inconsistent-return-statements if a never returning function is " "called then it will be considered as an explicit return statement " @@ -469,8 +470,8 @@ class RefactoringChecker(checkers.BaseTokenChecker): ), ) - def __init__(self, linter=None): - super().__init__(linter) + def __init__(self, linter): + super().__init__(linter, future_option_parsing=True) self._return_nodes = {} self._consider_using_with_stack = ConsiderUsingWithStack() self._init() @@ -486,7 +487,9 @@ def _init(self): def open(self): # do this in open since config not fully initialized in __init__ - self._never_returning_functions = set(self.config.never_returning_functions) + self._never_returning_functions = set( + self.linter.namespace.never_returning_functions + ) @cached_property def _dummy_rgx(self): @@ -1125,11 +1128,11 @@ def _check_nested_blocks(self, node): self._emit_nested_blocks_message_if_needed(nested_blocks) def _emit_nested_blocks_message_if_needed(self, nested_blocks): - if len(nested_blocks) > self.config.max_nested_blocks: + if len(nested_blocks) > self.linter.namespace.max_nested_blocks: self.add_message( "too-many-nested-blocks", node=nested_blocks[0], - args=(len(nested_blocks), self.config.max_nested_blocks), + args=(len(nested_blocks), self.linter.namespace.max_nested_blocks), ) def _emit_consider_using_with_if_needed(self, stack: Dict[str, nodes.NodeNG]): diff --git a/pylint/checkers/spelling.py b/pylint/checkers/spelling.py index f0c5effeb6..272fa06d64 100644 --- a/pylint/checkers/spelling.py +++ b/pylint/checkers/spelling.py @@ -263,44 +263,48 @@ class SpellingChecker(BaseTokenChecker): ), ) + def __init__(self, linter: "PyLinter") -> None: + super().__init__(linter, future_option_parsing=True) + def open(self): self.initialized = False self.private_dict_file = None if enchant is None: return - dict_name = self.config.spelling_dict + dict_name = self.linter.namespace.spelling_dict if not dict_name: return self.ignore_list = [ - w.strip() for w in self.config.spelling_ignore_words.split(",") + w.strip() for w in self.linter.namespace.spelling_ignore_words.split(",") ] # "param" appears in docstring in param description and # "pylint" appears in comments in pylint pragmas. self.ignore_list.extend(["param", "pylint"]) self.ignore_comment_directive_list = [ - w.strip() for w in self.config.spelling_ignore_comment_directives.split(",") + w.strip() + for w in self.linter.namespace.spelling_ignore_comment_directives.split(",") ] # Expand tilde to allow e.g. spelling-private-dict-file = ~/.pylintdict - if self.config.spelling_private_dict_file: - self.config.spelling_private_dict_file = os.path.expanduser( - self.config.spelling_private_dict_file + if self.linter.namespace.spelling_private_dict_file: + self.linter.namespace.spelling_private_dict_file = os.path.expanduser( + self.linter.namespace.spelling_private_dict_file ) - if self.config.spelling_private_dict_file: + if self.linter.namespace.spelling_private_dict_file: self.spelling_dict = enchant.DictWithPWL( - dict_name, self.config.spelling_private_dict_file + dict_name, self.linter.namespace.spelling_private_dict_file ) self.private_dict_file = open( # pylint: disable=consider-using-with - self.config.spelling_private_dict_file, "a", encoding="utf-8" + self.linter.namespace.spelling_private_dict_file, "a", encoding="utf-8" ) else: self.spelling_dict = enchant.Dict(dict_name) - if self.config.spelling_store_unknown_words: + if self.linter.namespace.spelling_store_unknown_words: self.unknown_words = set() self.tokenizer = get_tokenizer( @@ -374,14 +378,14 @@ def _check_spelling(self, msgid, line, line_num): continue # Store word to private dict or raise a message. - if self.config.spelling_store_unknown_words: + if self.linter.namespace.spelling_store_unknown_words: if lower_cased_word not in self.unknown_words: self.private_dict_file.write(f"{lower_cased_word}\n") self.unknown_words.add(lower_cased_word) else: # Present up to N suggestions. suggestions = self.spelling_dict.suggest(word) - del suggestions[self.config.max_spelling_suggestions :] + del suggestions[self.linter.namespace.max_spelling_suggestions :] line_segment = line[word_start_at:] match = re.search(rf"(\W|^)({word})(\W|$)", line_segment) if match: