fix: allow imports to be '_' prefixed#9308
Draft
dmadisetti wants to merge 2 commits into
Draft
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
for more information, see https://pre-commit.ci
akshayka
pushed a commit
that referenced
this pull request
Jul 23, 2026
## 📝 Summary Replaces #9308 and #9309. Closes #9151, closes #10223. A scoping change introduced in #8762 (0.22.0) made `_`-prefixed imports private. The intent is consistent with marimo's private-variable pattern, but three edge cases were mishandled: 1. References to **no-alias underscore imports** (`from pkg import _camera`) were mangled inside nested scopes (function bodies, decorators, class bases), producing `NameError: name '_cell_<id>_camera' is not defined` (#9151). These imports are deliberately defined under their **raw** name — the user has no control over the upstream symbol — so their references must stay raw everywhere. 2. **Content hashing** failed for underscore-aliased module imports used by cached functions in the same cell (`import marimo as _mo` + `@_mo.lru_cache` → `cannot pickle 'module' object`). 3. One cell's raw underscore import could **leak into other cells** through shared globals — but only when the importing cell happened to run first: order-dependent behavior with no reactive edge (the failure mode behind #10223's confusion). ## Intended behavior | Form | Defines | Same cell (incl. nested scopes) | Other cells | |---|---|---|---| | `import foo` | `foo`, public | works | shared, reactive | | `import foo as _f` / `import a.b as _f` | mangled `_f`, cell-local | works | NameError + hint | | `from a.b import _c` | raw `_c`, cell-local | works *(was NameError in nested scopes, #9151)* | NameError + hint *(was an order-dependent leak)* | | `import _private.submodule` | raw `_private`, cell-local | works | NameError + hint | | `from ibis import _` | raw `_`, cell-local | works | NameError + hint suggesting `from ibis import _ as lib` (#10223) | | `_x = ...` | mangled `_x`, cell-local | works | NameError + hint *(was a bare NameError exposing the mangled name)* | Cell-local imports never trigger `MultipleDefinitionError`: two cells may both `import numpy as _np` or `from pkg import _c`. Mangling imports wholesale (#9309's approach) was ruled out because `import _private.submodule` has no resolvable local name to mangle.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.