Skip to content

fix(python): keep function-local imports out of package re-exports - #5647

Closed
debojyoti10CC wants to merge 1 commit into
Graphify-Labs:v8from
debojyoti10CC:fix/function-local-import-followup
Closed

debojyoti10CC wants to merge 1 commit into
Graphify-Labs:v8from
debojyoti10CC:fix/function-local-import-followup

Conversation

@debojyoti10CC

Copy link
Copy Markdown
Contributor

What does this PR do?nnFollow-up to #5421. Upstream v8 already fixed the sibling-function leak. Two cases remained, and this PR fixes them on top of v8:nn- A function-local from m import x inside a package __init__.py was published as a package re-export. from pkg import x in 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. On v8 that already holds, so the test documents it.nn## Type of changenn- [x] Bug fixn- [x] Tests or CInn## Verification & Invariantsnn- Reproduced on v8: from pkg import run in app.py resolved to a call edge to pkg/helper.py through the function-local import in pkg/__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-local from ... import in __init__.py. Function-local import x is 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 on v8 without 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.

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]>
@github-actions

Copy link
Copy Markdown

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.

@github-actions github-actions Bot added the contributor Pull request from a returning community contributor label Nov 30, 2026

@graphify-labs graphify-labs Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Graphify review View in Graphify

Nothing blocking · 1 possible issue to check · Merge confidence 5/5

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

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

safishamsi added a commit that referenced this pull request Nov 30, 2026
…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]>
safishamsi added a commit that referenced this pull request Nov 30, 2026
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]>
@safishamsi

Copy link
Copy Markdown
Member

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. 🙏

@safishamsi safishamsi closed this Nov 30, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

contributor Pull request from a returning community contributor

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants