Skip to content

Commit f815e9f

Browse files
Fix cyclic-import edge exclusion with --jobs (#8820)
Follow-up to bf8051b.
1 parent 768c026 commit f815e9f

File tree

2 files changed

+39
-4
lines changed

2 files changed

+39
-4
lines changed

pylint/checkers/imports.py

+12-4
Original file line numberDiff line numberDiff line change
@@ -488,15 +488,23 @@ def close(self) -> None:
488488
for cycle in get_cycles(graph, vertices=vertices):
489489
self.add_message("cyclic-import", args=" -> ".join(cycle))
490490

491-
def get_map_data(self) -> defaultdict[str, set[str]]:
492-
return self.import_graph
491+
def get_map_data(
492+
self,
493+
) -> tuple[defaultdict[str, set[str]], defaultdict[str, set[str]]]:
494+
return (self.import_graph, self._excluded_edges)
493495

494496
def reduce_map_data(
495-
self, linter: PyLinter, data: list[defaultdict[str, set[str]]]
497+
self,
498+
linter: PyLinter,
499+
data: list[tuple[defaultdict[str, set[str]], defaultdict[str, set[str]]]],
496500
) -> None:
497501
self.import_graph = defaultdict(set)
498-
for graph in data:
502+
self._excluded_edges = defaultdict(set)
503+
for to_update in data:
504+
graph, excluded_edges = to_update
499505
self.import_graph.update(graph)
506+
self._excluded_edges.update(excluded_edges)
507+
500508
self.close()
501509

502510
def deprecated_modules(self) -> set[str]:

tests/test_check_parallel.py

+27
Original file line numberDiff line numberDiff line change
@@ -655,3 +655,30 @@ def test_cyclic_import_parallel(self) -> None:
655655
)
656656

657657
assert "cyclic-import" in linter.stats.by_msg
658+
659+
@pytest.mark.needs_two_cores
660+
def test_cyclic_import_parallel_disabled(self) -> None:
661+
tests_dir = Path("tests")
662+
package_path = Path("input") / "func_noerror_cycle"
663+
linter = PyLinter(reporter=Reporter())
664+
linter.register_checker(ImportsChecker(linter))
665+
666+
with _test_cwd(tests_dir):
667+
check_parallel(
668+
linter,
669+
jobs=2,
670+
files=[
671+
FileItem(
672+
name="input.func_noerror_cycle.a",
673+
filepath=str(package_path / "a.py"),
674+
modpath="input.func_noerror_cycle",
675+
),
676+
FileItem(
677+
name="input.func_noerror_cycle.b",
678+
filepath=str(package_path / "b.py"),
679+
modpath="input.func_noerror_cycle",
680+
),
681+
],
682+
)
683+
684+
assert "cyclic-import" not in linter.stats.by_msg

0 commit comments

Comments
 (0)