Skip to content

Commit

Permalink
Fix handling of -- as separator between positional args and flags (
Browse files Browse the repository at this point in the history
…#7551)

Co-authored-by: Pierre Sassoulas <pierre.sassoulas@gmail.com>
  • Loading branch information
DanielNoord and Pierre-Sassoulas committed Oct 2, 2022
1 parent 6291295 commit 1a9626a
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 6 deletions.
4 changes: 4 additions & 0 deletions doc/whatsnew/fragments/7003.bugfix
@@ -0,0 +1,4 @@
Fixed handling of ``--`` as separator between positional arguments and flags.
This was not actually fixed in 2.14.5.

Closes #7003, Refs #7096
9 changes: 7 additions & 2 deletions pylint/config/config_initialization.py
Expand Up @@ -72,12 +72,17 @@ def _config_initialization(
# the configuration file
parsed_args_list = linter._parse_command_line_configuration(args_list)

# Remove the positional arguments separator from the list of arguments if it exists
try:
parsed_args_list.remove("--")
except ValueError:
pass

# Check if there are any options that we do not recognize
unrecognized_options: list[str] = []
for opt in parsed_args_list:
if opt.startswith("--"):
if len(opt) > 2:
unrecognized_options.append(opt[2:])
unrecognized_options.append(opt[2:])
elif opt.startswith("-"):
unrecognized_options.append(opt[1:])
if unrecognized_options:
Expand Down
7 changes: 3 additions & 4 deletions tests/config/test_config.py
Expand Up @@ -148,11 +148,10 @@ def test_short_verbose(capsys: CaptureFixture) -> None:
assert "Using config file" in output.err


def test_argument_separator(capsys: CaptureFixture) -> None:
def test_argument_separator() -> None:
"""Check that we support using '--' to separate argument types.
Reported in https://github.com/PyCQA/pylint/issues/7003.
"""
Run(["--", str(EMPTY_MODULE)], exit=False)
output = capsys.readouterr()
assert not output.err
runner = Run(["--", str(EMPTY_MODULE)], exit=False)
assert not runner.linter.stats.by_msg

0 comments on commit 1a9626a

Please sign in to comment.