Repository navigation
Conversation
Merging this PR will not alter performance
Comparing Footnotes
|
The same logic for building the importer and imported module sets (and checking for shared descendants) was repeated in the chain and direct import queries. Assistant-model: Claude Code
Peter554
force-pushed
the
exclude-shared-descendants
branch
from
November 17, 2026 13:20
fbc8d4e to
f3ad50c
Compare
Adds the parameter to find_shortest_chain, find_shortest_chains, chain_exists and direct_import_exists. It allows searching between packages where one contains the other, by excluding the shared descendants from the outer package. Assistant-model: Claude Code
Peter554
force-pushed
the
exclude-shared-descendants
branch
from
November 17, 2026 13:25
f3ad50c to
8ce19f3
Compare
This was referenced Nov 17, 2026
Peter554
marked this pull request as ready for review
November 17, 2026 15:41
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
find_shortest_chain,find_shortest_chains,chain_existsanddirect_import_existsraiseValueError("Modules have shared descendants.")withas_packages=Truewhen one package contains the other. There's no way to ask for chains (or direct imports) between an inner package and the rest of the outer package, e.g. betweenpkg.innerand everything else inpkg.Import Linter needs this for
forbiddencontracts where the source and forbidden modules overlap - see import-linter/import-linter#423.Change
Adds
exclude_shared_descendants=Falseto the four methods. WhenTrue(andas_packages=True), the shared modules are removed from the outer package, so the search is between the inner package and the rest of the outer one. If the two packages are identical, nothing is left to search, so there are no chains.The default is unchanged, so existing callers still get the
ValueError.Commits
get_importer_and_imported_moduleshelper. Refactor only. The chain and direct import queries each built the importer and imported module sets (including descendants) and checked for shared descendants themselves. They now share one helper onGraph, next toget_module_descendants.exclude_shared_descendantsparameter. The behaviour change: the helper takes the new flag, which the four methods expose. Includes tests, docs and the changelog.Open questions
find_direct_imports_betweenalso still raises on shared descendants, but isn't exposed in the Python API, so I've left it.