Skip to content

Commit 1ef3b0b

Browse files
Support duplicate-code message with --jobs (#8757)
1 parent 2acca90 commit 1ef3b0b

File tree

5 files changed

+24
-2
lines changed

5 files changed

+24
-2
lines changed

doc/whatsnew/fragments/374.bugfix

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Support ``duplicate-code`` message when parallelizing with ``--jobs``.
2+
3+
Closes #374

pylint/checkers/similar.py

+3
Original file line numberDiff line numberDiff line change
@@ -889,8 +889,11 @@ def reduce_map_data(self, linter: PyLinter, data: list[list[LineSet]]) -> None:
889889
"""Reduces and recombines data into a format that we can report on.
890890
891891
The partner function of get_map_data()
892+
893+
Calls self.close() to actually calculate and report duplicate code.
892894
"""
893895
Similar.combine_mapreduce_data(self, linesets_collection=data)
896+
self.close()
894897

895898

896899
def register(linter: PyLinter) -> None:

pylint/lint/parallel.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ def check_parallel(
130130
"""Use the given linter to lint the files with given amount of workers (jobs).
131131
132132
This splits the work filestream-by-filestream. If you need to do work across
133-
multiple files, as in the similarity-checker, then implement the map/reduce mixin functionality.
133+
multiple files, as in the similarity-checker, then implement the map/reduce functionality.
134134
"""
135135
# The linter is inherited by all the pool's workers, i.e. the linter
136136
# is identical to the linter object here. This is required so that

tests/test_self.py

-1
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,6 @@ def test_parallel_execution(self) -> None:
233233
join(HERE, "functional", "a", "arguments.py"),
234234
],
235235
out=out,
236-
# We expect similarities to fail and an error
237236
code=MSG_TYPES_STATUS["E"],
238237
)
239238
assert (

tests/test_similar.py

+17
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,23 @@ def test_duplicate_code_raw_strings_all(self) -> None:
8282
expected_output=expected_output,
8383
)
8484

85+
@pytest.mark.needs_two_cores
86+
def test_duplicate_code_parallel(self) -> None:
87+
path = join(DATA, "raw_strings_all")
88+
expected_output = "Similar lines in 2 files"
89+
self._test_output(
90+
[
91+
path,
92+
"--disable=all",
93+
"--enable=duplicate-code",
94+
"--ignore-imports=no",
95+
"--ignore-signatures=no",
96+
"--min-similarity-lines=4",
97+
"--jobs=2",
98+
],
99+
expected_output=expected_output,
100+
)
101+
85102
def test_duplicate_code_raw_strings_disable_file(self) -> None:
86103
"""Tests disabling duplicate-code at the file level in a single file."""
87104
path = join(DATA, "raw_strings_disable_file")

0 commit comments

Comments
 (0)