From 09e7027374bca9f9fb6cfc8a508aae587712f146 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dani=C3=ABl=20van=20Noord?= <13665637+DanielNoord@users.noreply.github.com> Date: Thu, 30 Jun 2022 14:09:42 +0200 Subject: [PATCH] Fix handling of ``--`` as separator of positional arguments and flags --- doc/whatsnew/2/2.14/full.rst | 3 +++ pylint/config/config_initialization.py | 3 ++- tests/config/test_config.py | 10 ++++++++++ 3 files changed, 15 insertions(+), 1 deletion(-) diff --git a/doc/whatsnew/2/2.14/full.rst b/doc/whatsnew/2/2.14/full.rst index e8eca74f61..d4b94eec17 100644 --- a/doc/whatsnew/2/2.14/full.rst +++ b/doc/whatsnew/2/2.14/full.rst @@ -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? ---------------------------- diff --git a/pylint/config/config_initialization.py b/pylint/config/config_initialization.py index af47a4c6bb..7b412f9c24 100644 --- a/pylint/config/config_initialization.py +++ b/pylint/config/config_initialization.py @@ -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: diff --git a/tests/config/test_config.py b/tests/config/test_config.py index ed0b745ffa..47891aee25 100644 --- a/tests/config/test_config.py +++ b/tests/config/test_config.py @@ -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) + output = capsys.readouterr() + assert not output.err