Skip to content

fix: preseve top level names for name thrashing#9695

Merged
dmadisetti merged 1 commit into
mainfrom
dm/name-fix
May 27, 2026
Merged

fix: preseve top level names for name thrashing#9695
dmadisetti merged 1 commit into
mainfrom
dm/name-fix

Conversation

@dmadisetti
Copy link
Copy Markdown
Collaborator

📝 Summary

Closes #9693

We set class/function top level definitions to *name for their name to distinguish them from a normally named cell. Direct calls to ir conversion missed this detail resulting in immediate conversion from ir -> code in having redundant cell names.

This PR enforces the naming scheme for top level definitions, thus properly preserving the cell name reversion to _ on toplevel "demotion".

Copilot AI review requested due to automatic review settings May 26, 2026 22:25
@vercel
Copy link
Copy Markdown

vercel Bot commented May 26, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
marimo-docs Ready Ready Preview, Comment May 26, 2026 10:25pm

Request Review

Copy link
Copy Markdown
Contributor

@cubic-dev-ai cubic-dev-ai Bot left a comment

Choose a reason for hiding this comment

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

No issues found across 2 files

Re-trigger cubic

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR fixes a regression in IR → Python code generation where demoted top-level definitions (functions/classes) could incorrectly keep their original name in the emitted @app.cell signature, instead of reverting to the canonical anonymous cell name (def _(...):). This aligns generate_filecontents_from_ir() with the existing TOPLEVEL_CELL_PREFIX-based naming scheme used elsewhere so demotion logic can reliably anonymize names.

Changes:

  • Prefix FunctionCell/ClassCell names with TOPLEVEL_CELL_PREFIX during IR → Python generation so TopLevelExtraction can correctly revert demoted cells to _.
  • Add regression tests to ensure demoted @app.function serialization does not produce def foo(...): for the cell signature.
  • Add a (partial) test covering class-demotion naming behavior.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
marimo/_ast/codegen.py Ensures IR → Python generation marks top-level function/class cells with TOPLEVEL_CELL_PREFIX so demotion anonymizes cell names correctly.
tests/_ast/test_codegen.py Adds regression tests for demoted function/class cells to avoid preserving original definition names in @app.cell signatures.

Comment on lines +2232 to +2234
# The demoted cell signature must be `def _(...)`, not `def MyClass(...)`.
assert "@app.cell\ndef MyClass(" not in result
assert "@app.cell\ndef _(" in result
@dmadisetti dmadisetti requested a review from kirangadhave May 26, 2026 22:37
@kirangadhave kirangadhave added the bug Something isn't working label May 27, 2026
Copy link
Copy Markdown
Member

@kirangadhave kirangadhave left a comment

Choose a reason for hiding this comment

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

🚀

@dmadisetti dmadisetti merged commit b9de1f2 into main May 27, 2026
45 of 46 checks passed
@dmadisetti dmadisetti deleted the dm/name-fix branch May 27, 2026 03:02
@github-actions
Copy link
Copy Markdown

🚀 Development release published. You may be able to view the changes at https://marimo.app?v=0.23.9-dev9

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Decorated functions made into cells keep the function name

3 participants