feat(parser): expand Python from X import * in import_map#328
Conversation
103006b to
3b31b58
Compare
- Remove duplicate macOS-copy module files (analysis 2.py, enrich 2.py, enrich 3.py, exports 2.py, exports 3.py, graph_diff 2.py, jedi_resolver 2.py, memory 2.py, memory 3.py, token_benchmark 2.py) that tripped ruff N999. - Sort imports in main.py (ruff I001). - Drop unused parse_git_diff_ranges import in tools/review.py (ruff F401). - Add type-ignore for FastMCP._tool_manager private attribute access in main.py. CI on main has been red since PR tirth8205#94. This fixes it.
MCP tool calls were opening a fresh GraphStore (and SQLite connection) on every invocation. Cache one GraphStore per db_path and reuse it, falling back to a fresh connection if the cached one is dead. Thread-safe via a module-level lock.
Exact known-answer assertions for compute_risk_score and trace_flows, plus error-path coverage for parser on malformed input and module-cache eviction. - TestRiskScoreExact: 6 tests pinning risk score math (untested, tested, security keyword, caller fractions, 20-caller cap) - TestFlowExact: 4 tests for linear chain depth, cycles, single-file criticality, and non-test neighbors - TestParserErrorPaths: 8 tests for binary files, unknown extensions, syntax errors, empty files, CRLF, deeply nested AST, unicode - TestCacheEviction: oldest-half module cache eviction
Add three helpers: - `_resolve_star_imports`: walks top-level `import_from_statement` nodes, detects `wildcard_import`, resolves the source module to a file, and merges the exported names into the caller's import_map. - `_get_exported_names`: returns the public names a module exports, respecting `__all__` when present. Caches results per resolved path with a threading lock so concurrent parses share work safely. - `_extract_dunder_all`: parses `__all__ = [...]` at module scope. Wires star-import expansion into `parse_bytes` and the notebook concat path. Enables resolution of calls that come in via wildcard imports (e.g. `from constants import *` then `use_constant()`).
3b31b58 to
7717968
Compare
|
The wildcard-import idea at head |
|
Resolved and merged through current-main replacement PR #638.\n\nRetained behavior:\n- repository-local Python wildcard imports;\n- direct and explicit all exports;\n- relative and transitive wildcard chains;\n- notebook imports;\n- bounded, fingerprinted, thread-safe parser caching;\n- repository and symlink boundary enforcement;\n- fail-soft handling of imported-module parse errors.\n\nThe replacement preserves Gideon Zenz's co-author attribution and merged as 8c227dd.\n\nVerification:\n- focused parser coverage: 158 passed, 2 xpassed;\n- full local suite: 1,515 passed, 1 skipped, 2 xpassed;\n- Ruff, mypy, and diff checks passed;\n- all 11 GitHub checks passed, including Python 3.10–3.13 and native Windows. |
Port the viable behavior from PR tirth8205#328 (commit 7717968) onto the current parser. Expand direct, __all__, relative, transitive, and notebook imports without reading outside the configured repository; share a bounded, fingerprinted, thread-safe cache across worker parser instances and fail soft on imported-module errors. Co-authored-by: Gideon Zenz <91069374+gzenz@users.noreply.github.com>
Summary
Record star-imported names in
import_mapso downstream bare-call resolution can resolve them.Stacked PR approach
This is PR 3/16 in a stack that ports closed #158 into small, reviewable slices based on your feedback. Each branch contains this commit plus every earlier branch in the stack, so it applies cleanly on its own. The intended merge order is bottom-to-top.
Stack (merge order):
After you merge PR N, I rebase PRs N+1..16 on current main and force-push. Each PR ends up as a single commit on top of the previous one. Review only the newest commit in this PR; the rest will already be on main (or in earlier PRs in the stack).
All 16 branches are rebased on 072ab80. None re-attempts the closed lang-handler refactor.
Roadmap: restoring v7 loop-test parity
Measured impact on loop-test fixtures (Gadgetbridge Kotlin/Java, HealthAgent Python/TS):
Still deferred after this stack