Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix handling of -- as separator between positional args and flags #7551

Merged
merged 2 commits into from Oct 2, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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
DanielNoord marked this conversation as resolved.
Show resolved Hide resolved
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