Skip to content

Commit ca03a3e

Browse files
Correct 'similar' to 'symilar' when talking about the program
1 parent 2ba88b9 commit ca03a3e

File tree

6 files changed

+41
-40
lines changed

6 files changed

+41
-40
lines changed

doc/symilar.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
Symilar
44
-------
55

6-
The console script ``symilar`` finds copy pasted blocks in a set of files. It provides a command line interface to the ``Similar`` class, which includes the logic for
7-
Pylint's ``duplicate-code`` message.
6+
The console script ``symilar`` finds copy pasted block of text in a set of files. It provides a command line interface to check only the ``duplicate-code`` message.
7+
88
It can be invoked with::
99

1010
symilar [-d|--duplicates min_duplicated_lines] [-i|--ignore-comments] [--ignore-docstrings] [--ignore-imports] [--ignore-signatures] file1...

doc/whatsnew/fragments/9734.internal

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
All variables, classes, functions and file names containing the word 'similar', when it was,
2+
in fact, referring to 'symilar' (the standalone program for the duplicate-code check) were renamed
3+
to 'symilar'.
4+
5+
Closes #9734

pylint/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,9 +61,9 @@ def run_symilar(argv: Sequence[str] | None = None) -> NoReturn:
6161
6262
argv can be a sequence of strings normally supplied as arguments on the command line
6363
"""
64-
from pylint.checkers.similar import Run as SimilarRun
64+
from pylint.checkers.symilar import Run as SymilarRun
6565

66-
SimilarRun(argv or sys.argv[1:])
66+
SymilarRun(argv or sys.argv[1:])
6767

6868

6969
def modify_sys_path() -> None:

pylint/checkers/similar.py renamed to pylint/checkers/symilar.py

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -343,7 +343,7 @@ class Commonality(NamedTuple):
343343
snd_file_end: LineNumber
344344

345345

346-
class Similar:
346+
class Symilar:
347347
"""Finds copy-pasted lines of code in a project."""
348348

349349
def __init__(
@@ -751,18 +751,15 @@ def report_similarities(
751751

752752

753753
# wrapper to get a pylint checker from the similar class
754-
class SimilarChecker(BaseRawFileChecker, Similar):
754+
class SimilaritiesChecker(BaseRawFileChecker, Symilar):
755755
"""Checks for similarities and duplicated code.
756756
757757
This computation may be memory / CPU intensive, so you
758758
should disable it if you experience some problems.
759759
"""
760760

761-
# configuration section name
762761
name = "similarities"
763-
# messages
764762
msgs = MSGS
765-
# configuration options
766763
# for available dict keys/values see the optik parser 'add_option' method
767764
options: Options = (
768765
(
@@ -811,12 +808,11 @@ class SimilarChecker(BaseRawFileChecker, Similar):
811808
},
812809
),
813810
)
814-
# reports
815811
reports = (("RP0801", "Duplication", report_similarities),)
816812

817813
def __init__(self, linter: PyLinter) -> None:
818814
BaseRawFileChecker.__init__(self, linter)
819-
Similar.__init__(
815+
Symilar.__init__(
820816
self,
821817
min_lines=self.linter.config.min_similarity_lines,
822818
ignore_comments=self.linter.config.ignore_comments,
@@ -873,7 +869,7 @@ def close(self) -> None:
873869

874870
def get_map_data(self) -> list[LineSet]:
875871
"""Passthru override."""
876-
return Similar.get_map_data(self)
872+
return Symilar.get_map_data(self)
877873

878874
def reduce_map_data(self, linter: PyLinter, data: list[list[LineSet]]) -> None:
879875
"""Reduces and recombines data into a format that we can report on.
@@ -882,12 +878,12 @@ def reduce_map_data(self, linter: PyLinter, data: list[list[LineSet]]) -> None:
882878
883879
Calls self.close() to actually calculate and report duplicate code.
884880
"""
885-
Similar.combine_mapreduce_data(self, linesets_collection=data)
881+
Symilar.combine_mapreduce_data(self, linesets_collection=data)
886882
self.close()
887883

888884

889885
def register(linter: PyLinter) -> None:
890-
linter.register_checker(SimilarChecker(linter))
886+
linter.register_checker(SimilaritiesChecker(linter))
891887

892888

893889
def usage(status: int = 0) -> NoReturn:
@@ -944,7 +940,7 @@ def Run(argv: Sequence[str] | None = None) -> NoReturn:
944940
ignore_signatures = True
945941
if not args:
946942
usage(1)
947-
sim = Similar(
943+
sim = Symilar(
948944
min_lines, ignore_comments, ignore_docstrings, ignore_imports, ignore_signatures
949945
)
950946
for filename in args:

tests/checkers/unittest_symilar.py

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
import pytest
1010

11-
from pylint.checkers import similar
11+
from pylint.checkers import symilar
1212
from pylint.constants import IS_PYPY, PY39_PLUS
1313
from pylint.lint import PyLinter
1414
from pylint.testutils import GenericTestReporter as Reporter
@@ -31,7 +31,7 @@
3131
def test_ignore_comments() -> None:
3232
output = StringIO()
3333
with redirect_stdout(output), pytest.raises(SystemExit) as ex:
34-
similar.Run(["--ignore-comments", SIMILAR1, SIMILAR2])
34+
symilar.Run(["--ignore-comments", SIMILAR1, SIMILAR2])
3535
assert ex.value.code == 0
3636
assert (
3737
output.getvalue().strip()
@@ -60,7 +60,7 @@ def test_ignore_comments() -> None:
6060
def test_ignore_docstrings() -> None:
6161
output = StringIO()
6262
with redirect_stdout(output), pytest.raises(SystemExit) as ex:
63-
similar.Run(["--ignore-docstrings", SIMILAR1, SIMILAR2])
63+
symilar.Run(["--ignore-docstrings", SIMILAR1, SIMILAR2])
6464
assert ex.value.code == 0
6565
assert (
6666
output.getvalue().strip()
@@ -95,7 +95,7 @@ def test_ignore_docstrings() -> None:
9595
def test_ignore_imports() -> None:
9696
output = StringIO()
9797
with redirect_stdout(output), pytest.raises(SystemExit) as ex:
98-
similar.Run(["--ignore-imports", SIMILAR1, SIMILAR2])
98+
symilar.Run(["--ignore-imports", SIMILAR1, SIMILAR2])
9999
assert ex.value.code == 0
100100
assert (
101101
output.getvalue().strip()
@@ -108,7 +108,7 @@ def test_ignore_imports() -> None:
108108
def test_multiline_imports() -> None:
109109
output = StringIO()
110110
with redirect_stdout(output), pytest.raises(SystemExit) as ex:
111-
similar.Run([MULTILINE, MULTILINE])
111+
symilar.Run([MULTILINE, MULTILINE])
112112
assert ex.value.code == 0
113113
assert (
114114
output.getvalue().strip()
@@ -138,7 +138,7 @@ def test_multiline_imports() -> None:
138138
def test_ignore_multiline_imports() -> None:
139139
output = StringIO()
140140
with redirect_stdout(output), pytest.raises(SystemExit) as ex:
141-
similar.Run(["--ignore-imports", MULTILINE, MULTILINE])
141+
symilar.Run(["--ignore-imports", MULTILINE, MULTILINE])
142142
assert ex.value.code == 0
143143
assert (
144144
output.getvalue().strip()
@@ -151,7 +151,7 @@ def test_ignore_multiline_imports() -> None:
151151
def test_ignore_signatures_fail() -> None:
152152
output = StringIO()
153153
with redirect_stdout(output), pytest.raises(SystemExit) as ex:
154-
similar.Run([SIMILAR5, SIMILAR6])
154+
symilar.Run([SIMILAR5, SIMILAR6])
155155
assert ex.value.code == 0
156156
assert (
157157
output.getvalue().strip()
@@ -189,7 +189,7 @@ def example():
189189
def test_ignore_signatures_pass() -> None:
190190
output = StringIO()
191191
with redirect_stdout(output), pytest.raises(SystemExit) as ex:
192-
similar.Run(["--ignore-signatures", SIMILAR5, SIMILAR6])
192+
symilar.Run(["--ignore-signatures", SIMILAR5, SIMILAR6])
193193
assert ex.value.code == 0
194194
assert (
195195
output.getvalue().strip()
@@ -202,7 +202,7 @@ def test_ignore_signatures_pass() -> None:
202202
def test_ignore_signatures_class_methods_fail() -> None:
203203
output = StringIO()
204204
with redirect_stdout(output), pytest.raises(SystemExit) as ex:
205-
similar.Run([SIMILAR_CLS_B, SIMILAR_CLS_A])
205+
symilar.Run([SIMILAR_CLS_B, SIMILAR_CLS_A])
206206
assert ex.value.code == 0
207207
assert (
208208
output.getvalue().strip()
@@ -248,7 +248,7 @@ def _internal_func(
248248
def test_ignore_signatures_class_methods_pass() -> None:
249249
output = StringIO()
250250
with redirect_stdout(output), pytest.raises(SystemExit) as ex:
251-
similar.Run(["--ignore-signatures", SIMILAR_CLS_B, SIMILAR_CLS_A])
251+
symilar.Run(["--ignore-signatures", SIMILAR_CLS_B, SIMILAR_CLS_A])
252252
assert ex.value.code == 0
253253
assert (
254254
output.getvalue().strip()
@@ -261,7 +261,7 @@ def test_ignore_signatures_class_methods_pass() -> None:
261261
def test_ignore_signatures_empty_functions_fail() -> None:
262262
output = StringIO()
263263
with redirect_stdout(output), pytest.raises(SystemExit) as ex:
264-
similar.Run([EMPTY_FUNCTION_1, EMPTY_FUNCTION_2])
264+
symilar.Run([EMPTY_FUNCTION_1, EMPTY_FUNCTION_2])
265265
assert ex.value.code == 0
266266
assert (
267267
output.getvalue().strip()
@@ -285,7 +285,7 @@ def test_ignore_signatures_empty_functions_fail() -> None:
285285
def test_ignore_signatures_empty_functions_pass() -> None:
286286
output = StringIO()
287287
with redirect_stdout(output), pytest.raises(SystemExit) as ex:
288-
similar.Run(["--ignore-signatures", EMPTY_FUNCTION_1, EMPTY_FUNCTION_2])
288+
symilar.Run(["--ignore-signatures", EMPTY_FUNCTION_1, EMPTY_FUNCTION_2])
289289
assert ex.value.code == 0
290290
assert (
291291
output.getvalue().strip()
@@ -298,15 +298,15 @@ def test_ignore_signatures_empty_functions_pass() -> None:
298298
def test_no_hide_code_with_imports() -> None:
299299
output = StringIO()
300300
with redirect_stdout(output), pytest.raises(SystemExit) as ex:
301-
similar.Run(["--ignore-imports"] + 2 * [HIDE_CODE_WITH_IMPORTS])
301+
symilar.Run(["--ignore-imports"] + 2 * [HIDE_CODE_WITH_IMPORTS])
302302
assert ex.value.code == 0
303303
assert "TOTAL lines=32 duplicates=0 percent=0.00" in output.getvalue()
304304

305305

306306
def test_ignore_nothing() -> None:
307307
output = StringIO()
308308
with redirect_stdout(output), pytest.raises(SystemExit) as ex:
309-
similar.Run([SIMILAR1, SIMILAR2])
309+
symilar.Run([SIMILAR1, SIMILAR2])
310310
assert ex.value.code == 0
311311
assert (
312312
output.getvalue().strip()
@@ -329,7 +329,7 @@ def test_ignore_nothing() -> None:
329329
def test_lines_without_meaningful_content_do_not_trigger_similarity() -> None:
330330
output = StringIO()
331331
with redirect_stdout(output), pytest.raises(SystemExit) as ex:
332-
similar.Run([SIMILAR3, SIMILAR4])
332+
symilar.Run([SIMILAR3, SIMILAR4])
333333
assert ex.value.code == 0
334334
assert (
335335
output.getvalue().strip()
@@ -362,7 +362,7 @@ def test_help() -> None:
362362
output = StringIO()
363363
with redirect_stdout(output):
364364
try:
365-
similar.Run(["--help"])
365+
symilar.Run(["--help"])
366366
except SystemExit as ex:
367367
assert ex.code == 0
368368
else:
@@ -373,18 +373,18 @@ def test_no_args() -> None:
373373
output = StringIO()
374374
with redirect_stdout(output):
375375
try:
376-
similar.Run([])
376+
symilar.Run([])
377377
except SystemExit as ex:
378378
assert ex.code == 1
379379
else:
380380
pytest.fail("not system exit")
381381

382382

383383
def test_get_map_data() -> None:
384-
"""Tests that a SimilarChecker can return and reduce mapped data."""
384+
"""Tests that a SymilarChecker can return and reduce mapped data."""
385385
linter = PyLinter(reporter=Reporter())
386386
# Add a parallel checker to ensure it can map and reduce
387-
linter.register_checker(similar.SimilarChecker(linter))
387+
linter.register_checker(symilar.SimilaritiesChecker(linter))
388388
source_streams = (
389389
str(INPUT / "similar_lines_a.py"),
390390
str(INPUT / "similar_lines_b.py"),
@@ -473,7 +473,7 @@ def test_get_map_data() -> None:
473473

474474
# Manually perform a 'map' type function
475475
for source_fname in source_streams:
476-
sim = similar.SimilarChecker(PyLinter())
476+
sim = symilar.SimilaritiesChecker(PyLinter())
477477
sim.linter.set_option("ignore-imports", False)
478478
sim.linter.set_option("ignore-signatures", False)
479479
with open(source_fname, encoding="utf-8") as stream:
@@ -494,7 +494,7 @@ def test_get_map_data() -> None:
494494
def test_set_duplicate_lines_to_zero() -> None:
495495
output = StringIO()
496496
with redirect_stdout(output), pytest.raises(SystemExit) as ex:
497-
similar.Run(["--duplicates=0", SIMILAR1, SIMILAR2])
497+
symilar.Run(["--duplicates=0", SIMILAR1, SIMILAR2])
498498
assert ex.value.code == 0
499499
assert output.getvalue() == ""
500500

@@ -504,7 +504,7 @@ 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:
507-
similar.Run([f"-{v}=0", SIMILAR1, SIMILAR2])
507+
symilar.Run([f"-{v}=0", SIMILAR1, SIMILAR2])
508508
assert ex.value.code == 2
509509
assert "invalid literal for int() with base 10: '=0'" in output.getvalue()
510510

@@ -514,7 +514,7 @@ def test_space_short_form_option(v: str) -> None:
514514
"""Regression test for https://github.com/pylint-dev/pylint/issues/9343"""
515515
output = StringIO()
516516
with redirect_stdout(output), pytest.raises(SystemExit) as ex:
517-
similar.Run([f"-{v} 2", SIMILAR1, SIMILAR2])
517+
symilar.Run([f"-{v} 2", SIMILAR1, SIMILAR2])
518518
assert ex.value.code == 0
519519
assert "similar lines in" in output.getvalue()
520520

@@ -523,6 +523,6 @@ def test_bad_short_form_option() -> None:
523523
"""Regression test for https://github.com/pylint-dev/pylint/issues/9343"""
524524
output = StringIO()
525525
with redirect_stdout(output), pytest.raises(SystemExit) as ex:
526-
similar.Run(["-j=0", SIMILAR1, SIMILAR2])
526+
symilar.Run(["-j=0", SIMILAR1, SIMILAR2])
527527
assert ex.value.code == 2
528528
assert "option -j not recognized" in output.getvalue()

tests/test_similar.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
CLEAN_PATH = re.escape(dirname(dirname(__file__)) + os.path.sep)
2323

2424

25-
class TestSimilarCodeChecker:
25+
class TestSymilarCodeChecker:
2626
def _runtest(self, args: list[str], code: int) -> None:
2727
"""Runs the tests and sees if output code is as expected."""
2828
out = StringIO()

0 commit comments

Comments
 (0)