Skip to content

Commit f9839a1

Browse files
authored
Use argparse config handler on two checkers (#6120)
1 parent d1fc4af commit f9839a1

File tree

3 files changed

+28
-17
lines changed

3 files changed

+28
-17
lines changed

pylint/checkers/strings.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -677,8 +677,8 @@ class StringConstantChecker(BaseTokenChecker):
677677
# Unicode strings.
678678
UNICODE_ESCAPE_CHARACTERS = "uUN"
679679

680-
def __init__(self, *args, **kwargs):
681-
super().__init__(*args, **kwargs)
680+
def __init__(self, linter):
681+
super().__init__(linter, future_option_parsing=True)
682682
self.string_tokens = {} # token position -> (token value, next token)
683683

684684
def process_module(self, node: nodes.Module) -> None:
@@ -709,7 +709,7 @@ def process_tokens(self, tokens):
709709
start = (start[0], len(line[: start[1]].encode(encoding)))
710710
self.string_tokens[start] = (str_eval(token), next_token)
711711

712-
if self.config.check_quote_consistency:
712+
if self.linter.namespace.check_quote_consistency:
713713
self.check_for_consistent_string_delimiters(tokens)
714714

715715
@check_messages("implicit-str-concat")
@@ -783,7 +783,7 @@ def check_for_concatenated_strings(self, elements, iterable_type):
783783
if matching_token != elt.value and next_token is not None:
784784
if next_token.type == tokenize.STRING and (
785785
next_token.start[0] == elt.lineno
786-
or self.config.check_str_concat_over_line_jumps
786+
or self.linter.namespace.check_str_concat_over_line_jumps
787787
):
788788
self.add_message(
789789
"implicit-str-concat", line=elt.lineno, args=(iterable_type,)

pylint/checkers/typecheck.py

Lines changed: 23 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -883,6 +883,9 @@ class TypeChecker(BaseChecker):
883883
),
884884
)
885885

886+
def __init__(self, linter: "PyLinter") -> None:
887+
super().__init__(linter, future_option_parsing=True)
888+
886889
def open(self) -> None:
887890
py_version = get_global_option(self, "py-version")
888891
self._py310_plus = py_version >= (3, 10)
@@ -899,7 +902,7 @@ def _compiled_generated_members(self) -> Tuple[Pattern, ...]:
899902
# (surrounded by quote `"` and followed by a comma `,`)
900903
# REQUEST,aq_parent,"[a-zA-Z]+_set{1,2}"' =>
901904
# ('REQUEST', 'aq_parent', '[a-zA-Z]+_set{1,2}')
902-
generated_members = self.config.generated_members
905+
generated_members = self.linter.namespace.generated_members
903906
if isinstance(generated_members, str):
904907
gen = shlex.shlex(generated_members)
905908
gen.whitespace += ","
@@ -986,7 +989,7 @@ def visit_attribute(self, node: nodes.Attribute) -> None:
986989
]
987990
if (
988991
len(non_opaque_inference_results) != len(inferred)
989-
and self.config.ignore_on_opaque_inference
992+
and self.linter.namespace.ignore_on_opaque_inference
990993
):
991994
# There is an ambiguity in the inference. Since we can't
992995
# make sure that we won't emit a false positive, we just stop
@@ -995,7 +998,10 @@ def visit_attribute(self, node: nodes.Attribute) -> None:
995998
for owner in non_opaque_inference_results:
996999
name = getattr(owner, "name", None)
9971000
if _is_owner_ignored(
998-
owner, name, self.config.ignored_classes, self.config.ignored_modules
1001+
owner,
1002+
name,
1003+
self.linter.namespace.ignored_classes,
1004+
self.linter.namespace.ignored_modules,
9991005
):
10001006
continue
10011007

@@ -1024,8 +1030,8 @@ def visit_attribute(self, node: nodes.Attribute) -> None:
10241030
owner,
10251031
name,
10261032
self._mixin_class_rgx,
1027-
ignored_mixins=self.config.ignore_mixin_members,
1028-
ignored_none=self.config.ignore_none,
1033+
ignored_mixins=self.linter.namespace.ignore_mixin_members,
1034+
ignored_none=self.linter.namespace.ignore_none,
10291035
):
10301036
continue
10311037
missingattr.add((owner, name))
@@ -1080,12 +1086,12 @@ def _get_nomember_msgid_hint(self, node, owner):
10801086
hint = ""
10811087
else:
10821088
msg = "no-member"
1083-
if self.config.missing_member_hint:
1089+
if self.linter.namespace.missing_member_hint:
10841090
hint = _missing_member_hint(
10851091
owner,
10861092
node.attrname,
1087-
self.config.missing_member_hint_distance,
1088-
self.config.missing_member_max_choices,
1093+
self.linter.namespace.missing_member_hint_distance,
1094+
self.linter.namespace.missing_member_max_choices,
10891095
)
10901096
else:
10911097
hint = ""
@@ -1335,7 +1341,7 @@ def visit_call(self, node: nodes.Call) -> None:
13351341

13361342
# Has the function signature changed in ways we cannot reliably detect?
13371343
if hasattr(called, "decorators") and decorated_with(
1338-
called, self.config.signature_mutators
1344+
called, self.linter.namespace.signature_mutators
13391345
):
13401346
return
13411347

@@ -1709,7 +1715,7 @@ def visit_with(self, node: nodes.With) -> None:
17091715
# Check if we are dealing with a function decorated
17101716
# with contextlib.contextmanager.
17111717
if decorated_with(
1712-
inferred.parent, self.config.contextmanager_decorators
1718+
inferred.parent, self.linter.namespace.contextmanager_decorators
17131719
):
17141720
continue
17151721
# If the parent of the generator is not the context manager itself,
@@ -1737,7 +1743,9 @@ def visit_with(self, node: nodes.With) -> None:
17371743
scope = inferred_path.scope()
17381744
if not isinstance(scope, nodes.FunctionDef):
17391745
continue
1740-
if decorated_with(scope, self.config.contextmanager_decorators):
1746+
if decorated_with(
1747+
scope, self.linter.namespace.contextmanager_decorators
1748+
):
17411749
break
17421750
else:
17431751
self.add_message(
@@ -1754,7 +1762,7 @@ def visit_with(self, node: nodes.With) -> None:
17541762
if not has_known_bases(inferred):
17551763
continue
17561764
# Just ignore mixin classes.
1757-
if self.config.ignore_mixin_members:
1765+
if self.linter.namespace.ignore_mixin_members:
17581766
if inferred.name[-5:].lower() == "mixin":
17591767
continue
17601768

@@ -1999,6 +2007,9 @@ class IterableChecker(BaseChecker):
19992007
),
20002008
}
20012009

2010+
def __init__(self, linter: "PyLinter") -> None:
2011+
super().__init__(linter, future_option_parsing=True)
2012+
20022013
@staticmethod
20032014
def _is_asyncio_coroutine(node):
20042015
if not isinstance(node, nodes.Call):

pylint/config/arguments_manager.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ def __init__(self) -> None:
2222
self.namespace = argparse.Namespace()
2323
"""Namespace for all options."""
2424

25-
self._arg_parser = argparse.ArgumentParser(prog="pylint")
25+
self._arg_parser = argparse.ArgumentParser(prog="pylint", allow_abbrev=False)
2626
"""The command line argument parser."""
2727

2828
self._argument_groups_dict: Dict[str, argparse._ArgumentGroup] = {}

0 commit comments

Comments
 (0)