feat: classify conditional imports - #33
Conversation
|
Validation:
Note: full |
|
I found one blocker around relative conditional imports.
Please add coverage for conditional relative imports, especially |
|
@copilot resolve the merge conflicts in this pull request |
|
@copilot resolve the merge conflicts in this pull request |
1 similar comment
|
@copilot resolve the merge conflicts in this pull request |
Resolved by merging |
|
One blocker before merge: _import_from_module_names now rewrites every from . import a, b to .a / .b, including non-conditional ones. When the alias isn't a module file — e.g. from . import VERSION where VERSION lives in init.py, a C-extension sibling, or a namespace package — _resolve_relative_import falls through to return (candidate_base + ".py", True), so we emit an external edge whose target is an absolute filesystem path, and we lose the internal init.py edge we used to produce. That label is used verbatim by per_external_edge, project_nodes(include_externals=True), and the CSV/HTML rows, so it can produce false external-dependency violations. Please fall back to the package target when . doesn't resolve, and add a regression test for from . import . Two non-blocking notes: Conditional edges now carry two kinds (e.g. relative|conditional), so the import_kinds column in graph reports changes shape for existing projects. Worth a line in the README/changelog since report consumers may parse it. |
Pull Request
Adds first-class classification for conditional imports inside
tryblocks that handleImportErrororModuleNotFoundError.These imports are now marked with
ImportKind.CONDITIONAL_IMPORT, allowing dependency graphs and reports to distinguish optional/fallback dependencies from regular runtime imports.This PR includes regression tests for conditional imports in raw import extraction and graph extraction, plus a short README note documenting the behavior.
Change Type