Skip to content

Fix #666: Probe submodules for python package imports#676

Open
kishansaaai wants to merge 1 commit into
repowise-dev:mainfrom
kishansaaai:fix-666-python-resolver
Open

Fix #666: Probe submodules for python package imports#676
kishansaaai wants to merge 1 commit into
repowise-dev:mainfrom
kishansaaai:fix-666-python-resolver

Conversation

@kishansaaai

Copy link
Copy Markdown

Summary

This PR fixes the false-positive unreachable_file reports on Python router modules caused by the resolver missing submodules when they are imported via a package __init__.py.

The root cause was that resolve_python_import would resolve statements like from repowise.server.routers import workspace strictly to repowise/server/routers/__init__.py, meaning the submodules themselves never received inbound edges and were falsely flagged by the dead-code analyzer with in_degree=0.

Changes:

  • Added a resolve_python_import_all helper function in repowise.core.ingestion.resolvers.python.
  • resolve_python_import_all resolves the base package, then properly iterates over the Import.imported_names to probe for <name>.py and <name>/__init__.py submodules in the package directory.
  • Updated _resolve_imports in graph/builder.py to route Python resolutions through this new function, appending missing edges.

Related Issues

Fixes #666

Test Plan

  • Tests pass (pytest)
  • Lint passes (ruff check .)
  • Web build passes (npm run build) (if frontend changes)

Added a dedicated regression test (test_python_resolver.py) ensuring resolve_python_import_all properly identifies and returns submodule file paths when a module uses the from pkg import submodule1, submodule2 format.

Checklist

  • My code follows the project's code style
  • I have added tests for new functionality
  • All existing tests still pass
  • I have updated documentation if needed

@repowise-bot

repowise-bot Bot commented Jul 3, 2026

Copy link
Copy Markdown

✅ Health: 7.6 (unchanged)
1 file moved · 1 hotspot · 5 hidden couplings · 2 with fix history

🩹 Review priority (files here with the most recent bug-fix history — defects cluster, so review these first)

File Score Δ Why
.../resolvers/python.py 8.8 → 7.2 ▼ -1.6 🔻 introduced nested complexity

💡 .../resolvers/python.py: Flatten the control flow. Pull early-return guards to the top, extract the deepest branch into a helper, and consider replacing nested conditionals with a strategy table or dispatch dict.

🔥 Hotspot touched (1)
  • .../graph/builder.py — 14 commits/90d, 4 dependents · primary owner: Raghav Chamadiya (88%)
🔗 Hidden coupling (1 file)
  • .../graph/builder.py co-changes with these files (not in this PR):
    • .../ingestion/call_resolver.py (4× — 🟢 routine)
    • .../ingestion/parser.py (4× — 🟢 routine)
    • .../phases/ingestion.py (4× — 🟢 routine)
    • .../graph/_resolvers.py (4× — 🟢 routine)
    • .../ingestion/models.py (3× — 🟢 routine)

📊 Full report · ⭐ Star Repowise · 📥 Install bot · Last updated 2026-07-03 20:36 UTC
Silence on a single PR with [skip repowise] in the title · Per-repo toggle on repowise.dev/settings?tab=bot

@swati510

swati510 commented Jul 7, 2026

Copy link
Copy Markdown
Collaborator

Thanks for tackling #666. Two things are blocking merge.

CI is red because the two new tests don't run. They build Import(module_type=…, range_start=…, is_type_only=…), and Import (in packages/core/src/repowise/core/ingestion/models.py) has none of those fields. Its real fields are raw_statement, module_path, imported_names, is_relative, resolved_file, and the first three are missing here, so both tests raise TypeError. Could you rebuild them with the real fields and confirm pytest tests/unit/ingestion/test_python_resolver.py passes locally?

The dead-code regression that #666 asked for is also missing. Nothing yet proves a router imported only at the package level stops being flagged as unreachable. A small end-to-end test on that shape would lock it in.

Two smaller notes. Namespace packages (no __init__.py, PEP 420) and the bare from . import submodule form still aren't rescued, so it would help to handle them or note them as known gaps. There's also an accidental comment de-indent at python.py:70 in a function this PR doesn't otherwise change.

Happy to re-review once CI is green.

@repowise-bot repowise-bot Bot added repowise:health-decline Repowise: repository health score declined repowise:hotspot Repowise: touches a temporal hotspot file labels Jul 8, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

repowise:health-decline Repowise: repository health score declined repowise:hotspot Repowise: touches a temporal hotspot file

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] Python resolver misses from package import submodule, causing false dead-code on router modules

2 participants