Repository navigation
fix(python): keep function-local imports out of package re-exports - #5647
debojyoti10CC wants to merge 1 commit into
Conversation
A `from m import x` inside a function in a package __init__.py binds `x` only inside that function. It was still published as a package re-export, so `from pkg import x` in another module resolved to the function-local import. Adds regression tests for this and for a call inside a nested function to a name its enclosing function imports. Co-Authored-By: Claude Haiku 5.5 <[email protected]>
|
Thanks for the pull request, @debojyoti10CC. A maintainer will review it soon. Want to talk it through while it is in review? Come join us on our Discord server. For longer-form discussion there is also GitHub Discussions. A couple of things that speed up review: make sure the test suite passes on Python 3.11 and 3.13, and that the change keeps extraction deterministic. |
There was a problem hiding this comment.
Graphify review 
1 possible issue to check · High impact
The change stops imports inside functions in a package __init__.py from being recorded as package exports.
1 possible issue we couldn't confirm
- Imports inside a class body in a package
__init__.pyare still exported as package re-exports ·graphify/extractors/resolution.py:3629
They don't change the score.
Code graph · 4674 functions depend on this change
- 2 functions became more coupled.
extract()(1427 callers),_collect_python_symbol_resolution_facts()(2 callers). - 49 of 658 test files are affected by this change.
- Gate, test list and every flagged function: in the Graphify check.
Reviewed a2ff160
…der schema 60 The 59->60 bump (landed with the apex/swift extractor fixes this release) already invalidates stale caches; this records the other extraction-output changes riding that bump: bash caller-var bases (#5563), GitHub Actions run: step extraction (#5565), Python package re-export scoping (#5647), and co-indexed symlink identities (#5617). Co-Authored-By: Claude Opus 4.8 <[email protected]>
Extractor accuracy (Swift #5641, Apex #5627, Python #5647, TypeScript #5604/#5614/#5612, Bash caller-var #5602), GitHub Actions run-step extraction (#5603), incremental correctness (#5634/#5638/#5636), symlink and semantic-cache fixes (#5617/#5618), export/report hardening and perf (#5643/#5644/#5645/#5646/#5619/#5620/#5621), and CLI/docs/skill/install work (#5629/#5628/#5626/#5624/#5623/#5625/#5642/#5583). AST cache schema 59 to 60; Swift/Apex/Python/Bash/GHA inputs re-extract on first build. Co-Authored-By: Claude Opus 4.8 <[email protected]>
|
Landed in v0.9.124 (just released to PyPI), cherry-picked with your authorship preserved so it shows under your name in the history. Thanks @debojyoti10CC for keeping function-local imports out of package re-exports — verified green in the full suite and, where applicable, smoke-tested against the published package. 🙏 |
What does this PR do?nnFollow-up to #5421. Upstream
v8already fixed the sibling-function leak. Two cases remained, and this PR fixes them on top ofv8:nn- A function-localfrom m import xinside a package__init__.pywas published as a package re-export.from pkg import xin another module then resolved to a name that is only bound inside a function. It is no longer exported.nnA regression test covers a call inside a nested function to a name its enclosing function imports. It asserts the call binds to the imported definition and not to a same-named definition in this file. Onv8that already holds, so the test documents it.nn## Type of changenn- [x] Bug fixn- [x] Tests or CInn## Verification & Invariantsnn- Reproduced onv8:from pkg import runinapp.pyresolved to a call edge topkg/helper.pythrough the function-local import inpkg/__init__.py.n- Invariant: a name bound by a function-local import is visible only inside that function, and never as a package-level export. Extraction stays deterministic.n- Limitations: covers function-localfrom ... importin__init__.py. Function-localimport xis unchanged.nn## How was this tested?nntextnpytest tests/test_python_external_import_calls.py tests/test_symbol_resolution.py -> 60 passednpytest tests -k "python or symbol or import or resolution" -> 1924 passed, 3 skippednnnBoth new regression tests fail onv8without this change.nn## Graphify-specific checklistnn- [ ] I updated generated skill artifacts. Not applicable: no skill fragments changed.n- [x] I confirmed that AST/structural extraction remains deterministic (no ambient state dependencies like ENV variables).n- [x] I reviewed changes for security implications (no unsafe interpolation into shell/Python).n- [x] I confirmed no API keys or local-only graph data are included.n- [x] (If applicable) I disclosed AI authorship in my commit messages.