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 of positional arguments and flags #7096

Merged
merged 1 commit into from
Jun 30, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
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
3 changes: 3 additions & 0 deletions doc/whatsnew/2/2.14/full.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ What's New in Pylint 2.14.5?
Release date: TBA


* Fixed handling of ``--`` as separator between positional arguments and flags.

Closes #7003

What's New in Pylint 2.14.4?
----------------------------
Expand Down
3 changes: 2 additions & 1 deletion pylint/config/config_initialization.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,8 @@ def _config_initialization(
unrecognized_options: list[str] = []
for opt in parsed_args_list:
if opt.startswith("--"):
unrecognized_options.append(opt[2:])
if len(opt) > 2:
unrecognized_options.append(opt[2:])
elif opt.startswith("-"):
unrecognized_options.append(opt[1:])
if unrecognized_options:
Expand Down
10 changes: 10 additions & 0 deletions tests/config/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,3 +116,13 @@ def test_short_verbose(capsys: CaptureFixture) -> None:
Run([str(EMPTY_MODULE), "-v"], exit=False)
output = capsys.readouterr()
assert "Using config file" in output.err


def test_argument_separator(capsys: CaptureFixture) -> 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)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we test that option are taken into account for example here an init-hook that print ?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could, but I'm fairly confident this should work. The code that this is changing is a pylint hack on top of argparse. We parse arguments with parse_known_args so argparse doesn't complain about unknown options and leaves that to us.
I simply didn't know that this is allowed so this wasn't excluded from the list of unknown options. argparse probably does dit automatically in the normale parse_args.

output = capsys.readouterr()
assert not output.err