Raise ValueError when a module is assigned to more than one layer (#165)#304
Raise ValueError when a module is assigned to more than one layer (#165)#304HarperZ9 wants to merge 1 commit into
Conversation
find_illegal_dependencies_for_layers panicked with an opaque
pyo3_runtime.PanicException ("no entry found for key") when the same module
appeared in more than one layer. Add a Python-side guard that raises a
descriptive ValueError naming the repeated module(s) before the call reaches
the Rust extension, and cover it with tests.
Fixes python-grimp#165.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Merging this PR will not alter performance
Comparing Footnotes
|
|
Heads-up on the red CI here: it is not caused by this change. |
|
Thanks for the PR! I'll have a look in the next few days. |
Fixes #165.
Problem
find_illegal_dependencies_for_layersterminates with an opaque Rust panic when the same module is assigned to more than one layer:A module cannot sit at two different levels at once, so this is an input error that should be reported clearly rather than surfacing as a panic from the extension.
Change
Add a Python-side guard (
_check_layers_do_not_share_modules) that runs after_parse_layersand raises a descriptiveValueErrornaming the repeated module(s) before the Rust call:It works on the parsed
Layer.module_tails, so it covers the simple-string,set, andLayerinput forms.Tests
TestInvalidLayersintests/unit/application/graph/test_layers.pyfor the string andLayerduplicate cases.pytest tests/unit tests/functional-> 828 passed, 1 skipped.ruff check,ruff format --check, andmypyon the changed files pass.CHANGELOG.rstentry underlatest.