Skip to content

Fix cyclic-import edge exclusion with --jobs #8820

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 12 additions & 4 deletions pylint/checkers/imports.py
Original file line number Diff line number Diff line change
Expand Up @@ -488,15 +488,23 @@ def close(self) -> None:
for cycle in get_cycles(graph, vertices=vertices):
self.add_message("cyclic-import", args=" -> ".join(cycle))

def get_map_data(self) -> defaultdict[str, set[str]]:
return self.import_graph
def get_map_data(
self,
) -> tuple[defaultdict[str, set[str]], defaultdict[str, set[str]]]:
return (self.import_graph, self._excluded_edges)

def reduce_map_data(
self, linter: PyLinter, data: list[defaultdict[str, set[str]]]
self,
linter: PyLinter,
data: list[tuple[defaultdict[str, set[str]], defaultdict[str, set[str]]]],
) -> None:
self.import_graph = defaultdict(set)
for graph in data:
self._excluded_edges = defaultdict(set)
for to_update in data:
graph, excluded_edges = to_update
self.import_graph.update(graph)
self._excluded_edges.update(excluded_edges)

self.close()

def deprecated_modules(self) -> set[str]:
Expand Down
27 changes: 27 additions & 0 deletions tests/test_check_parallel.py
Original file line number Diff line number Diff line change
Expand Up @@ -655,3 +655,30 @@ def test_cyclic_import_parallel(self) -> None:
)

assert "cyclic-import" in linter.stats.by_msg

@pytest.mark.needs_two_cores
def test_cyclic_import_parallel_disabled(self) -> None:
tests_dir = Path("tests")
package_path = Path("input") / "func_noerror_cycle"
linter = PyLinter(reporter=Reporter())
linter.register_checker(ImportsChecker(linter))

with _test_cwd(tests_dir):
check_parallel(
linter,
jobs=2,
files=[
FileItem(
name="input.func_noerror_cycle.a",
filepath=str(package_path / "a.py"),
modpath="input.func_noerror_cycle",
),
FileItem(
name="input.func_noerror_cycle.b",
filepath=str(package_path / "b.py"),
modpath="input.func_noerror_cycle",
),
],
)

assert "cyclic-import" not in linter.stats.by_msg