Skip to content

Commit c4e9afe

Browse files
authored
Finalize _parse_command_line_configuration (#6189)
1 parent 48e6585 commit c4e9afe

4 files changed

Lines changed: 17 additions & 15 deletions

File tree

pylint/config/arguments_manager.py

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@
55
"""Arguments manager class used to handle command-line arguments and options."""
66

77
import argparse
8-
from typing import TYPE_CHECKING, Dict, List
8+
import sys
9+
from typing import TYPE_CHECKING, Dict, List, Optional
910

1011
from pylint.config.argument import (
1112
_Argument,
@@ -33,7 +34,6 @@ def __init__(self) -> None:
3334
self._arg_parser = argparse.ArgumentParser(
3435
prog="pylint",
3536
usage="%(prog)s [options]",
36-
allow_abbrev=False,
3737
formatter_class=_HelpFormatter,
3838
)
3939
"""The command line argument parser."""
@@ -145,15 +145,17 @@ def _parse_configuration_file(self, config_data: Dict[str, str]) -> None:
145145
# TODO: This should parse_args instead of parse_known_args
146146
self.namespace = self._arg_parser.parse_known_args(arguments, self.namespace)[0]
147147

148-
def _parse_command_line_configuration(self, arguments: List[str]) -> None:
148+
def _parse_command_line_configuration(
149+
self, arguments: Optional[List[str]] = None
150+
) -> List[str]:
149151
"""Parse the arguments found on the command line into the namespace."""
150-
# pylint: disable-next=fixme
151-
# TODO: This should parse_args instead of parse_known_args
152-
self.namespace = self._arg_parser.parse_known_args(arguments, self.namespace)[0]
152+
arguments = sys.argv[1:] if arguments is None else arguments
153153

154-
# pylint: disable-next=fixme
155-
# TODO: This should return a list of arguments with the option arguments removed
156-
# just as PyLinter.load_command_line_configuration does
154+
self.namespace, parsed_args = self._arg_parser.parse_known_args(
155+
arguments, self.namespace
156+
)
157+
158+
return parsed_args
157159

158160
def _parse_plugin_configuration(self) -> None:
159161
# pylint: disable-next=fixme

pylint/config/config_initialization.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ def _config_initialization(
7070

7171
# Load command line arguments
7272
try:
73-
parsed_args_list = linter.load_command_line_configuration(args_list)
73+
linter.load_command_line_configuration(args_list)
7474
except SystemExit as exc:
7575
if exc.code == 2: # bad options
7676
exc.code = 32
@@ -89,7 +89,7 @@ def _config_initialization(
8989

9090
# Second we parse any options from the command line, so they can override
9191
# the configuration file
92-
linter._parse_command_line_configuration(args_list)
92+
parsed_args_list = linter._parse_command_line_configuration(args_list)
9393

9494
# Lastly we parse any options from plugins
9595
linter._parse_plugin_configuration()

pylint/config/deprecation_actions.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ def __init__(
3333
super().__init__(
3434
option_strings,
3535
dest,
36-
"+",
36+
1,
3737
const,
3838
default,
3939
type,
@@ -78,7 +78,7 @@ def __init__(
7878
super().__init__(
7979
option_strings,
8080
dest,
81-
"+",
81+
1,
8282
const,
8383
default,
8484
type,

tests/config/test_argparse_config.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,8 @@ def test_new_names() -> None:
7171
@staticmethod
7272
def test_old_names() -> None:
7373
"""Check that we correctly double assign old name options."""
74-
run = Run([EMPTY_MODULE, "--ignore=test"], exit=False)
75-
assert run.linter.namespace.ignore == ["test"]
74+
run = Run([EMPTY_MODULE, "--ignore=test,test_two"], exit=False)
75+
assert run.linter.namespace.ignore == ["test", "test_two"]
7676
assert run.linter.namespace.ignore == run.linter.namespace.black_list
7777
assert run.linter.namespace.ignore_patterns == [re.compile("^\\.#")]
7878
assert (

0 commit comments

Comments
 (0)