Raise ModuleNotPresent for absent modules in direct-import queries (#113)#303
Raise ModuleNotPresent for absent modules in direct-import queries (#113)#303HarperZ9 wants to merge 1 commit into
Conversation
find_modules_that_directly_import silently returned an empty set (and the underlying Rust call panics) for a module not in the graph, and find_modules_directly_imported_by had no guard at all. Apply the existing ModuleNotPresent guard pattern used by squash_module/is_module_squashed to both, add docstrings, and cover with regression tests. Fixes python-grimp#113. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Merging this PR will not alter performance
Comparing Footnotes
|
|
Heads up on the two red checks, both look unrelated to this change. The lint failure is The The change itself is Python only (the |
|
Heads-up on the red CI here: it is not caused by this change. |
Fixes #113.
Problem
ImportGraph.find_modules_that_directly_importhandled an absent moduleinconsistently with the rest of the API: it silently returned an empty
set()(masking the missing module), while the underlying Rust call panics for an
absent module, as noted by the existing
# TODO.Its sibling
find_modules_directly_imported_byhad no guard at all and wouldsurface the raw Rust panic for an absent module.
Other query/manipulation methods (
squash_module,is_module_squashed, ...)already raise
grimp.exceptions.ModuleNotPresentin this situation.Change
Apply the existing
ModuleNotPresentguard pattern to bothfind_modules_that_directly_importandfind_modules_directly_imported_by, soan absent module raises
ModuleNotPresentwith the same message format usedelsewhere, and add docstrings documenting the behaviour.
Behaviour change
find_modules_that_directly_importpreviously returnedset()for an absentmodule; it now raises
ModuleNotPresent, matching the issue title and the restof the API. No internal callers relied on the previous empty-set behaviour.
Tests
tests/unit/application/graph/test_direct_imports.py.pytest tests/unit tests/functional-> 828 passed, 1 skipped.ruff check,ruff format --check, andmypyon the changed files all pass.CHANGELOG.rstentry underlatest.