Skip to content

Commit 6de2ebc

Browse files
[symilar] Fix the short form options that weren't being processed properly
Closes #9343
1 parent 86a5313 commit 6de2ebc

File tree

3 files changed

+7
-6
lines changed

3 files changed

+7
-6
lines changed

doc/whatsnew/fragments/9343.bugfix

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1-
Fixed a crash in ``symilar`` when the ``-d`` option was not properly recognized.
1+
Fixed a crash in ``symilar`` when the ``-d`` or ``-i`` short option were not properly recognized.
2+
It's still impossible to do ``-d=1`` (you must do ``-d 1``).
23

34
Closes #9343

pylint/checkers/similar.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -906,7 +906,7 @@ def Run(argv: Sequence[str] | None = None) -> NoReturn:
906906
if argv is None:
907907
argv = sys.argv[1:]
908908

909-
s_opts = "hdi"
909+
s_opts = "hd:i:"
910910
l_opts = [
911911
"help",
912912
"duplicates=",

tests/checkers/unittest_similar.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -499,14 +499,14 @@ def test_set_duplicate_lines_to_zero() -> None:
499499
assert output.getvalue() == ""
500500

501501

502-
@pytest.mark.parametrize("v", ["d", "i"])
502+
@pytest.mark.parametrize("v", ["d"])
503503
def test_bad_equal_short_form_option(v: str) -> None:
504504
"""Regression test for https://github.com/pylint-dev/pylint/issues/9343"""
505505
output = StringIO()
506506
with redirect_stdout(output), pytest.raises(SystemExit) as ex:
507507
similar.Run([f"-{v}=0", SIMILAR1, SIMILAR2])
508508
assert ex.value.code == 2
509-
assert "option -= not recognized" in output.getvalue()
509+
assert "invalid literal for int() with base 10: '=0'" in output.getvalue()
510510

511511

512512
@pytest.mark.parametrize("v", ["i", "d"])
@@ -515,8 +515,8 @@ def test_space_short_form_option(v: str) -> None:
515515
output = StringIO()
516516
with redirect_stdout(output), pytest.raises(SystemExit) as ex:
517517
similar.Run([f"-{v} 2", SIMILAR1, SIMILAR2])
518-
assert ex.value.code == 2
519-
assert "option - not recognized" in output.getvalue()
518+
assert ex.value.code == 0
519+
assert "similar lines in" in output.getvalue()
520520

521521

522522
def test_bad_short_form_option() -> None:

0 commit comments

Comments
 (0)