Skip to content

A reactive notebook for Python — run reproducible experiments, query with SQL, execute as a script, deploy as an app, and version with git. Stored as pure Python. All in a modern, AI-native editor.

feat: release reusable functions (#4560)

Dylan Madisettibeea536a99a9
diff --git a/frontend/src/components/app-config/user-config-form.tsx b/frontend/src/components/app-config/user-config-form.tsx
index bee919bfa9..39067feef6 100644
--- a/frontend/src/components/app-config/user-config-form.tsx
+++ b/frontend/src/components/app-config/user-config-form.tsx
@@ -1349,31 +1349,6 @@ export const UserConfigForm: React.FC = () => {
</div>
)}
/>
- <FormField
- control={form.control}
- name="experimental.toplevel_defs"
- render={({ field }) => (
- <div className="flex flex-col gap-y-1">
- <FormItem className={formItemClasses}>
- <FormLabel className="font-normal">
- Library Save Format
- </FormLabel>
- <FormControl>
- <Checkbox
- data-testid="toplevel-defs-checkbox"
- checked={field.value === true}
- onCheckedChange={field.onChange}
- />
- </FormControl>
- </FormItem>
- <FormDescription>
- Enable saving in an experimental file format for marimo.
- This will expose functions that are defined in their own
- cell for function reuse and import by other programs.
- </FormDescription>{" "}
- </div>
- )}
- />
<FormField
control={form.control}
name="experimental.table_charts"
diff --git a/frontend/src/components/editor/actions/useNotebookActions.tsx b/frontend/src/components/editor/actions/useNotebookActions.tsx
index 938656dc15..e71ee0d96a 100644
--- a/frontend/src/components/editor/actions/useNotebookActions.tsx
+++ b/frontend/src/components/editor/actions/useNotebookActions.tsx
@@ -85,7 +85,6 @@ import { AddDatabaseDialogContent } from "../database/add-database-form";
import { useHideAllMarkdownCode } from "./useHideAllMarkdownCode";
import { useSectionCollapse } from "./useSectionCollapse";
import { Constants } from "@/core/constants";
-import { getFeatureFlag } from "@/core/config/feature-flag";
const NOOP_HANDLER = (event?: Event) => {
event?.preventDefault();
@@ -392,7 +391,6 @@ export function useNotebookActions() {
{
icon: <DiamondPlusIcon size={14} strokeWidth={1.5} />,
label: "Add setup cell",
- hidden: !getFeatureFlag("toplevel_defs"),
handle: () => {
upsertSetupCell({
code: "# Initialization code that runs before all other cells",
diff --git a/frontend/src/core/config/feature-flag.tsx b/frontend/src/core/config/feature-flag.tsx
index b28ef0249e..142ebdf0d7 100644
--- a/frontend/src/core/config/feature-flag.tsx
+++ b/frontend/src/core/config/feature-flag.tsx
@@ -13,7 +13,6 @@ export interface ExperimentalFeatures {
scratchpad: boolean;
rtc_v2: boolean;
reactive_tests: boolean;
- toplevel_defs: boolean;
table_charts: boolean;
// Add new feature flags here
}
@@ -25,7 +24,6 @@ const defaultValues: ExperimentalFeatures = {
scratchpad: true,
rtc_v2: false,
reactive_tests: false,
- toplevel_defs: false,
table_charts: false,
};
diff --git a/marimo/_ast/codegen.py b/marimo/_ast/codegen.py
index 1c0b465858..f81d926e59 100644
--- a/marimo/_ast/codegen.py
+++ b/marimo/_ast/codegen.py
@@ -17,7 +17,6 @@ from marimo._ast.compiler import compile_cell
from marimo._ast.names import DEFAULT_CELL_NAME, SETUP_CELL_NAME
from marimo._ast.toplevel import TopLevelExtraction, TopLevelStatus
from marimo._ast.visitor import Name
-from marimo._config.manager import get_default_config_manager
from marimo._types.ids import CellId_t
if sys.version_info < (3, 10):
@@ -44,10 +43,9 @@ def pop_setup_cell(
code: list[str],
names: list[str],
configs: list[CellConfig],
- toplevel_fn: bool,
) -> Optional[CellImpl]:
# Find the cell named setup, compile, and remove the index from all lists.
- if SETUP_CELL_NAME not in names or not toplevel_fn:
+ if SETUP_CELL_NAME not in names:
return None
setup_index = names.index(SETUP_CELL_NAME)
try:
@@ -267,7 +265,7 @@ def generate_unparsable_cell(
def serialize_cell(
- extraction: TopLevelExtraction, status: TopLevelStatus, toplevel_fn: bool
+ extraction: TopLevelExtraction, status: TopLevelStatus
) -> str:
if status.is_unparsable:
return generate_unparsable_cell(
@@ -275,11 +273,7 @@ def serialize_cell(
)
cell = status._cell
assert cell is not None
- if not toplevel_fn:
- return to_functiondef(
- cell, status.name, extraction.unshadowed, None, fn="cell"
- )
- elif status.is_cell:
+ if status.is_cell:
return to_functiondef(
cell,
status.name,
@@ -313,66 +307,25 @@ def generate_app_constructor(config: Optional[_AppConfig]) -> str:
return format_tuple_elements("app = marimo.App(...)", kwargs)
-def _classic_export(
- fndefs: list[str],
- header_comments: Optional[str],
- config: Optional[_AppConfig],
-) -> str:
- filecontents = "".join(
- "import marimo"
- + "\n\n"
- + f'__generated_with = "{__version__}"'
- + "\n"
- + generate_app_constructor(config)
- + "\n\n\n"
- + "\n\n\n".join(fndefs)
- + "\n\n\n"
- + 'if __name__ == "__main__":'
- + "\n"
- + indent_text("app.run()")
- )
-
- if header_comments:
- filecontents = header_comments.rstrip() + "\n\n" + filecontents
- return filecontents + "\n"
-
-
def generate_filecontents(
codes: list[str],
names: list[str],
cell_configs: list[CellConfig],
config: Optional[_AppConfig] = None,
header_comments: Optional[str] = None,
- _toplevel_fn: bool = False,
) -> str:
"""Translates a sequences of codes (cells) to a Python file"""
- # Until an appropriate means of controlling top-level functions exists,
- # Let's keep it disabled by default.
- toplevel_fn = (
- get_default_config_manager(current_path=None)
- .get_config()
- .get("experimental", {})
- .get("toplevel_defs", False)
- ) or _toplevel_fn
-
# Update old internal cell names to the new ones
for idx, name in enumerate(names):
if name == "__":
names[idx] = DEFAULT_CELL_NAME
- # TODO: replace with dedicated cell
- setup_cell = pop_setup_cell(codes, names, cell_configs, toplevel_fn)
+ setup_cell = pop_setup_cell(codes, names, cell_configs)
toplevel_defs: set[Name] = set()
if setup_cell:
toplevel_defs = set(setup_cell.defs)
extraction = TopLevelExtraction(codes, names, cell_configs, toplevel_defs)
- cell_blocks = [
- serialize_cell(extraction, status, toplevel_fn)
- for status in extraction
- ]
-
- if not toplevel_fn:
- return _classic_export(cell_blocks, header_comments, config)
+ cell_blocks = [serialize_cell(extraction, status) for status in extraction]
filecontents = []
if header_comments is not None:
diff --git a/marimo/_ast/toplevel.py b/marimo/_ast/toplevel.py
index e5bf273dc8..d8fe1c3953 100644
--- a/marimo/_ast/toplevel.py
+++ b/marimo/_ast/toplevel.py
@@ -387,7 +387,7 @@ class TopLevelExtraction:
from marimo._ast.codegen import pop_setup_cell
- setup = pop_setup_cell(codes, names, cell_configs, True)
+ setup = pop_setup_cell(codes, names, cell_configs)
if setup:
return cls(codes, names, cell_configs, setup.defs)
return cls(codes, names, cell_configs, set())
diff --git a/marimo/_runtime/runner/hooks_post_execution.py b/marimo/_runtime/runner/hooks_post_execution.py
index 0a04336b2a..6c9fdce99d 100644
--- a/marimo/_runtime/runner/hooks_post_execution.py
+++ b/marimo/_runtime/runner/hooks_post_execution.py
@@ -330,7 +330,7 @@ def _broadcast_outputs(
@kernel_tracer.start_as_current_span("render_toplevel_defs")
-def _render_toplevel_defs(
+def render_toplevel_defs(
cell: CellImpl,
runner: cell_runner.Runner,
run_result: cell_runner.RunResult,
@@ -347,7 +347,7 @@ def _render_toplevel_defs(
@kernel_tracer.start_as_current_span("run_pytest")
-def _attempt_pytest(
+def attempt_pytest(
cell: CellImpl,
runner: cell_runner.Runner,
run_result: cell_runner.RunResult,
@@ -402,4 +402,6 @@ POST_EXECUTION_HOOKS: list[PostExecutionHookType] = [
# other hooks take a long time (broadcast outputs can take a long time
# if a formatter is slow).
_set_status_idle,
+ # NB. Other hooks are added ad-hoc or manually due to priority.
+ # Consider implementing priority sort to keep everything more centralized.
]
diff --git a/marimo/_runtime/runtime.py b/marimo/_runtime/runtime.py
index 6b9c9c4781..12e1eb419d 100644
--- a/marimo/_runtime/runtime.py
+++ b/marimo/_runtime/runtime.py
@@ -136,7 +136,10 @@ from marimo._runtime.runner.hooks import (
PREPARATION_HOOKS,
)
from marimo._runtime.runner.hooks_on_finish import OnFinishHookType
-from marimo._runtime.runner.hooks_post_execution import PostExecutionHookType
+from marimo._runtime.runner.hooks_post_execution import (
+ PostExecutionHookType,
+ render_toplevel_defs,
+)
from marimo._runtime.runner.hooks_pre_execution import PreExecutionHookType
from marimo._runtime.runner.hooks_preparation import PreparationHookType
from marimo._runtime.scratch import SCRATCH_CELL_ID
@@ -518,18 +521,13 @@ class Kernel:
# Adds in a post_execution hook to run pytest immediately
if user_config["runtime"].get("reactive_tests", False):
from marimo._runtime.runner.hooks_post_execution import (
- _attempt_pytest,
+ attempt_pytest,
)
- self._post_execution_hooks.append(_attempt_pytest)
-
- # Adds in a post_execution hook to run pytest immediately
- if user_config.get("experimental", {}).get("toplevel_defs", False):
- from marimo._runtime.runner.hooks_post_execution import (
- _render_toplevel_defs,
- )
+ self._post_execution_hooks.append(attempt_pytest)
- self._post_execution_hooks.append(_render_toplevel_defs)
+ # Must be last to properly trigger render.
+ self._post_execution_hooks.append(render_toplevel_defs)
self._globals_lock = threading.RLock()
self._completion_worker_started = False
diff --git a/marimo/_server/print.py b/marimo/_server/print.py
index bde1384152..e49b047516 100644
--- a/marimo/_server/print.py
+++ b/marimo/_server/print.py
@@ -120,6 +120,7 @@ def print_experimental_features(config: MarimoConfig) -> None:
"sql_engines",
"secrets",
"reactive_tests",
+ "toplevel_defs",
}
keys = keys - finished_experiments
diff --git a/marimo/_tutorials/dataflow.py b/marimo/_tutorials/dataflow.py
index 57c5ac15d9..7a0ed7b460 100644
--- a/marimo/_tutorials/dataflow.py
+++ b/marimo/_tutorials/dataflow.py
@@ -10,7 +10,7 @@
import marimo
-__generated_with = "0.12.2"
+__generated_with = "0.12.10"
app = marimo.App()
@@ -259,14 +259,14 @@ def _(mo):
def _():
planet = "Mars"
planet
- return (planet,)
+ return
@app.cell
def _():
planet = "Earth"
planet
- return (planet,)
+ return
@app.cell(hide_code=True)
@@ -298,13 +298,13 @@ def _(mo):
@app.cell
def _():
count = 0
- return (count,)
+ return
@app.cell
def _():
count += 1
- return (count,)
+ return
@app.cell(hide_code=True)
@@ -439,7 +439,7 @@ def _():
state = namespace()
state.number = 0
- return namespace, state
+ return (state,)
@app.cell(hide_code=True)
diff --git a/marimo/_tutorials/for_jupyter_users.py b/marimo/_tutorials/for_jupyter_users.py
index ac5ea34081..07f4f352e9 100644
--- a/marimo/_tutorials/for_jupyter_users.py
+++ b/marimo/_tutorials/for_jupyter_users.py
@@ -2,12 +2,12 @@
import marimo
-__generated_with = "0.9.30"
+__generated_with = "0.12.10"
app = marimo.App(app_title="marimo for Jupyter users")
@app.cell(hide_code=True)
-def __(mo):
+def _(mo):
mo.md(
r"""
# marimo for Jupyter users
@@ -20,7 +20,7 @@ def __(mo):
@app.cell(hide_code=True)
-def __(mo):
+def _(mo):
mo.md(
r"""
## Reactive execution
@@ -34,19 +34,19 @@ def __(mo):
@app.cell
-def __():
+def _():
x = 0; x
return (x,)
@app.cell
-def __(x):
+def _(x):
y = x + 1; y
- return (y,)
+ return
@app.cell(hide_code=True)
-def __(mo):
+def _(mo):
mo.md(
r"""
marimo 'reacts' to the change in `x` and automatically recalculates `y`!
@@ -63,7 +63,7 @@ def __(mo):
@app.cell(hide_code=True)
-def __(mo):
+def _(mo):
mo.md(
r"""
### Why?
@@ -83,7 +83,7 @@ def __(mo):
@app.cell(hide_code=True)
-def __(mo):
+def _(mo):
mo.md(
"""
## Interactive elements built-in
@@ -96,26 +96,26 @@ def __(mo):
@app.cell
-def __():
+def _():
import marimo as mo
return (mo,)
@app.cell
-def __(mo):
+def _(mo):
slider = mo.ui.slider(start=1, stop=10, label="$x$")
slider
return (slider,)
@app.cell
-def __(slider):
+def _(slider):
slider.value
return
@app.cell(hide_code=True)
-def __(mo):
+def _(mo):
mo.md(
rf"""
**Explanation.** marimo is both a notebook and a library. Import `marimo as
@@ -132,7 +132,7 @@ def __(mo):
@app.cell(hide_code=True)
-def __(mo):
+def _(mo):
mo.md(
r"""
## Shareable as apps
@@ -152,7 +152,7 @@ def __(mo):
@app.cell(hide_code=True)
-def __(mo):
+def _(mo):
mo.md(
r"""
## Cell order
@@ -164,19 +164,19 @@ def __(mo):
@app.cell
-def __(z):
+def _(z):
z.value
return
@app.cell
-def __(mo):
+def _(mo):
z = mo.ui.slider(1, 10, label="$z$"); z
return (z,)
@app.cell(hide_code=True)
-def __(mo):
+def _(mo):
mo.md(
r"""
This lets you arrange your cells in the way that makes the most sense to you. For example, put helper functions and imports at the bottom of a notebook, like an appendix.
@@ -188,7 +188,7 @@ def __(mo):
@app.cell(hide_code=True)
-def __(mo):
+def _(mo):
mo.md(
r"""
## Re-assigning variables
@@ -200,25 +200,25 @@ def __(mo):
@app.cell
-def __():
+def _():
df = 0
return (df,)
@app.cell
-def __():
+def _():
df = 1
return (df,)
@app.cell
-def __(df):
+def _(df):
results = df.groupby(["my_column"]).sum()
- return (results,)
+ return
@app.cell(hide_code=True)
-def __(mo):
+def _(mo):
mo.md(
r"""
**Explanation.** `results` depends on `df`, but which value of `df` should it use? Reactivity makes it impossible to answer this question in a sensible way, so marimo disallows variable reassignment.
@@ -234,7 +234,7 @@ def __(mo):
@app.cell(hide_code=True)
-def __(mo):
+def _(mo):
mo.md(
rf"""
## Markdown
@@ -246,7 +246,7 @@ def __(mo):
@app.cell
-def __(mo, slider):
+def _(mo, slider):
mo.md(
f"""
The value of {slider} is {slider.value}.
@@ -256,7 +256,7 @@ def __(mo, slider):
@app.cell(hide_code=True)
-def __(mo):
+def _(mo):
mo.md(
r"""
**Explanation.** By lifting Markdown into Python, marimo lets you construct
@@ -271,7 +271,7 @@ def __(mo):
@app.cell(hide_code=True)
-def __(mo):
+def _(mo):
mo.md(
r"""
## Notebook files
@@ -293,7 +293,7 @@ def __(mo):
@app.cell(hide_code=True)
-def __(mo):
+def _(mo):
mo.md(
r"""
## Parting thoughts
diff --git a/marimo/_tutorials/intro.py b/marimo/_tutorials/intro.py
index 0eb9e7c529..c4ca31a295 100644
--- a/marimo/_tutorials/intro.py
+++ b/marimo/_tutorials/intro.py
@@ -2,12 +2,12 @@
import marimo
-__generated_with = "0.9.2"
+__generated_with = "0.12.10"
app = marimo.App()
@app.cell
-def __():
+def _():
import marimo as mo
mo.md("# Welcome to marimo! 🌊🍃")
@@ -15,13 +15,13 @@ def __():
@app.cell
-def __(mo):
+def _(mo):
slider = mo.ui.slider(1, 22)
return (slider,)
@app.cell
-def __(mo, slider):
+def _(mo, slider):
mo.md(
f"""
marimo is a **reactive** Python notebook.
@@ -37,7 +37,7 @@ def __(mo, slider):
@app.cell(hide_code=True)
-def __(mo):
+def _(mo):
mo.accordion(
{
"Tip: disabling automatic execution": mo.md(
@@ -59,7 +59,7 @@ def __(mo):
@app.cell(hide_code=True)
-def __(mo):
+def _(mo):
mo.md(
"""
Tip: This is a tutorial notebook. You can create your own notebooks
@@ -70,7 +70,7 @@ def __(mo):
@app.cell(hide_code=True)
-def __(mo):
+def _(mo):
mo.md(
"""
## 1. Reactive execution
@@ -91,7 +91,7 @@ def __(mo):
@app.cell(hide_code=True)
-def __(changed, mo):
+def _(changed, mo):
(
mo.md(
f"""
@@ -118,13 +118,13 @@ def __(changed, mo):
@app.cell
-def __():
+def _():
changed = False
return (changed,)
@app.cell(hide_code=True)
-def __(mo):
+def _(mo):
mo.accordion(
{
"Tip: execution order": (
@@ -142,7 +142,7 @@ def __(mo):
@app.cell(hide_code=True)
-def __(mo):
+def _(mo):
mo.md(
"""
**Global names must be unique.** To enable reactivity, marimo imposes a
@@ -154,7 +154,7 @@ def __(mo):
@app.cell(hide_code=True)
-def __(mo):
+def _(mo):
mo.accordion(
{
"Tip: encapsulation": (
@@ -169,7 +169,7 @@ def __(mo):
@app.cell(hide_code=True)
-def __(mo):
+def _(mo):
mo.accordion(
{
"Tip: private variables": (
@@ -184,7 +184,7 @@ def __(mo):
@app.cell(hide_code=True)
-def __(mo):
+def _(mo):
mo.md(
"""
## 2. UI elements
@@ -202,37 +202,37 @@ def __(mo):
@app.cell
-def __(mo):
+def _(mo):
mo.md("""**🌊 Some UI elements.** Try interacting with the below elements.""")
return
@app.cell
-def __(mo):
+def _(mo):
icon = mo.ui.dropdown(["🍃", "🌊", "✨"], value="🍃")
return (icon,)
@app.cell
-def __(icon, mo):
+def _(icon, mo):
repetitions = mo.ui.slider(1, 16, label=f"number of {icon.value}: ")
return (repetitions,)
@app.cell
-def __(icon, repetitions):
+def _(icon, repetitions):
icon, repetitions
return
@app.cell
-def __(icon, mo, repetitions):
+def _(icon, mo, repetitions):
mo.md("# " + icon.value * repetitions.value)
return
@app.cell(hide_code=True)
-def __(mo):
+def _(mo):
mo.md(
"""
## 3. marimo is just Python
@@ -255,7 +255,7 @@ def __(mo):
@app.cell(hide_code=True)
-def __(mo):
+def _(mo):
mo.md(
"""
## 4. Running notebooks as apps
@@ -272,7 +272,7 @@ def __(mo):
@app.cell(hide_code=True)
-def __(mo):
+def _(mo):
mo.md(
"""
## 5. The `marimo` command-line tool
@@ -330,7 +330,7 @@ def __(mo):
@app.cell(hide_code=True)
-def __(mo):
+def _(mo):
mo.md(
"""
## 6. The marimo editor
@@ -342,19 +342,19 @@ def __(mo):
@app.cell
-def __(mo, tips):
+def _(mo, tips):
mo.accordion(tips)
return
@app.cell(hide_code=True)
-def __(mo):
+def _(mo):
mo.md("""## Finally, a fun fact""")
return
@app.cell(hide_code=True)
-def __(mo):
+def _(mo):
mo.md(
"""
The name "marimo" is a reference to a type of algae that, under
@@ -367,7 +367,7 @@ def __(mo):
@app.cell(hide_code=True)
-def __():
+def _():
tips = {
"Saving": (
"""
diff --git a/marimo/_tutorials/layout.py b/marimo/_tutorials/layout.py
index df8671bacf..bcdce2fddd 100644
--- a/marimo/_tutorials/layout.py
+++ b/marimo/_tutorials/layout.py
@@ -2,12 +2,12 @@
import marimo
-__generated_with = "0.9.30"
+__generated_with = "0.12.10"
app = marimo.App()
@app.cell(hide_code=True)
-def __(mo):
+def _(mo):
mo.md(
"""
# Layout
@@ -20,7 +20,7 @@ def __(mo):
@app.cell(hide_code=True)
-def __(mo):
+def _(mo):
mo.md(
"""
## Rows and columns
@@ -32,7 +32,7 @@ def __(mo):
@app.cell
-def __(mo):
+def _(mo):
mo.hstack(
[mo.ui.text(label="hello"), mo.ui.slider(1, 10, label="slider")],
justify="start",
@@ -41,13 +41,13 @@ def __(mo):
@app.cell
-def __(mo):
+def _(mo):
mo.vstack([mo.ui.text(label="world"), mo.ui.number(1, 10, label="number")])
return
@app.cell
-def __(mo):
+def _(mo):
grid = mo.vstack(
[
mo.hstack(
@@ -69,11 +69,11 @@ def __(mo):
plots!).
"""
)
- return (grid,)
+ return
@app.cell(hide_code=True)
-def __(mo):
+def _(mo):
mo.md(
"""
**Customization.**
@@ -85,7 +85,7 @@ def __(mo):
@app.cell
-def __(mo):
+def _(mo):
justify = mo.ui.dropdown(
["start", "center", "end", "space-between", "space-around"],
value="space-between",
@@ -102,14 +102,14 @@ def __(mo):
@app.cell
-def __(mo):
+def _(mo):
size = mo.ui.slider(label="box size", start=60, stop=500)
mo.hstack([size], justify="center")
return (size,)
@app.cell
-def __(align, boxes, gap, justify, mo, wrap):
+def _(align, boxes, gap, justify, mo, wrap):
mo.hstack(
boxes,
align=align.value,
@@ -121,7 +121,7 @@ def __(align, boxes, gap, justify, mo, wrap):
@app.cell
-def __(align, boxes, gap, mo):
+def _(align, boxes, gap, mo):
mo.vstack(
boxes,
align=align.value,
@@ -131,7 +131,7 @@ def __(align, boxes, gap, mo):
@app.cell
-def __(mo, size):
+def _(mo, size):
def create_box(num=1):
box_size = size.value + num * 10
return mo.Html(
@@ -140,11 +140,11 @@ def __(mo, size):
boxes = [create_box(i) for i in range(1, 5)]
- return boxes, create_box
+ return (boxes,)
@app.cell(hide_code=True)
-def __(mo):
+def _(mo):
mo.accordion(
{
"Documentation: `mo.hstack`": mo.doc(mo.hstack),
@@ -155,7 +155,7 @@ def __(mo):
@app.cell(hide_code=True)
-def __(mo):
+def _(mo):
mo.md(
"""
**Justifying `Html`.** While you can center or right-justify any object
@@ -168,25 +168,25 @@ def __(mo):
@app.cell
-def __(mo):
+def _(mo):
mo.md("""This markdown is left-justified.""")
return
@app.cell
-def __(mo):
+def _(mo):
mo.md("This markdown is centered.").center()
return
@app.cell
-def __(mo):
+def _(mo):
mo.md("This markdown is right-justified.").right()
return
@app.cell(hide_code=True)
-def __(mo):
+def _(mo):
mo.accordion(
{
"Documentation: `Html.center`": mo.doc(mo.Html.center),
@@ -198,7 +198,7 @@ def __(mo):
@app.cell(hide_code=True)
-def __(mo):
+def _(mo):
mo.md(
"""
## Accordion
@@ -210,13 +210,13 @@ def __(mo):
@app.cell(hide_code=True)
-def __(mo):
+def _(mo):
mo.md("""An accordion can contain multiple items:""")
return
@app.cell
-def __(mo):
+def _(mo):
mo.accordion(
{
"Multiple items": "By default, only one item can be open at a time",
@@ -232,7 +232,7 @@ def __(mo):
@app.cell(hide_code=True)
-def __(mo):
+def _(mo):
mo.md(
"""
## Tabs
@@ -244,7 +244,7 @@ def __(mo):
@app.cell
-def __(mo):
+def _(mo):
_settings = mo.vstack(
[
mo.md("**Edit User**"),
@@ -271,13 +271,13 @@ def __(mo):
@app.cell(hide_code=True)
-def __(mo):
+def _(mo):
mo.accordion({"Documentation: `mo.ui.tabs`": mo.doc(mo.ui.tabs)})
return
@app.cell
-def __(mo):
+def _(mo):
_t = [
mo.md("**Hello!**"),
mo.md(r"$f(x)$"),
@@ -298,13 +298,13 @@ def __(mo):
@app.cell(hide_code=True)
-def __(mo):
+def _(mo):
mo.accordion({"Documentation: `mo.tree`": mo.doc(mo.tree)})
return
@app.cell(hide_code=True)
-def __(mo):
+def _(mo):
mo.md(
"""
## Callout
@@ -317,7 +317,7 @@ def __(mo):
@app.cell
-def __(mo):
+def _(mo):
callout_kind = mo.ui.dropdown(
["neutral", "warn", "success", "info", "danger"], value="neutral"
)
@@ -325,7 +325,7 @@ def __(mo):
@app.cell
-def __(callout_kind, mo):
+def _(callout_kind, mo):
mo.md(
f"""
**This is a callout!**
@@ -339,13 +339,13 @@ def __(callout_kind, mo):
@app.cell(hide_code=True)
-def __(mo):
+def _(mo):
mo.accordion({"Documentation: `mo.callout`": mo.doc(mo.callout)})
return
@app.cell
-def __():
+def _():
import marimo as mo
return (mo,)
diff --git a/marimo/_tutorials/sql.py b/marimo/_tutorials/sql.py
index 0dd5533b50..abfbf55526 100644
--- a/marimo/_tutorials/sql.py
+++ b/marimo/_tutorials/sql.py
@@ -1,3 +1,4 @@
+# Copyright 2025 Marimo. All rights reserved.
# /// script
# requires-python = ">=3.12"
# dependencies = [
@@ -12,7 +13,7 @@
import marimo
-__generated_with = "0.12.8"
+__generated_with = "0.12.10"
app = marimo.App(width="medium")
@@ -69,14 +70,7 @@ def _():
has_pandas_installed = True
except ImportError:
pass
- return (
- duckdb,
- has_duckdb_installed,
- has_pandas_installed,
- has_polars_installed,
- pandas,
- polars,
- )
+ return has_duckdb_installed, has_polars_installed
@app.cell(hide_code=True)
@@ -206,7 +200,7 @@ def _(has_polars_installed):
import pandas as pd
df = pd.DataFrame(_data)
- return df, pd, pl
+ return (df,)
@app.cell(hide_code=True)
@@ -349,13 +343,7 @@ def _(mo, result, token_prefix):
import plotly.graph_objects as go
return go.Figure(data=[go.Histogram(x=result["count"])])
- return (
- render_altair,
- render_chart,
- render_charting_library,
- render_matplotlib,
- render_plotly,
- )
+ return (render_chart,)
@app.cell(hide_code=True)
@@ -388,7 +376,7 @@ def _(mo):
@app.cell
-def _(cars, mo):
+def _(mo):
cars = mo.sql(
f"""
-- Download a CSV and create an in-memory table; this is optional.
@@ -450,7 +438,7 @@ def _(filtered_cars, mo):
def _():
import marimo as mo
import random
- return mo, random
+ return (mo,)
@app.cell(hide_code=True)
diff --git a/marimo/_tutorials/ui.py b/marimo/_tutorials/ui.py
index a414c0fa80..61268729bd 100644
--- a/marimo/_tutorials/ui.py
+++ b/marimo/_tutorials/ui.py
@@ -2,7 +2,7 @@
import marimo
-__generated_with = "0.10.6"
+__generated_with = "0.12.10"
app = marimo.App()
diff --git a/tests/_ast/codegen_data/test_generate_filecontents.py b/tests/_ast/codegen_data/test_generate_filecontents.py
index 83f26134f3..5c22f50250 100644
--- a/tests/_ast/codegen_data/test_generate_filecontents.py
+++ b/tests/_ast/codegen_data/test_generate_filecontents.py
@@ -14,7 +14,7 @@ def one():
def two():
x = 0
xx = 1
- return x, xx
+ return (x,)
@app.cell
@@ -27,7 +27,7 @@ def three(x):
def four(np, x, y):
# comment
z = np.array(x + y)
- return (z,)
+ return
@app.cell
diff --git a/tests/_ast/codegen_data/test_generate_filecontents_async.py b/tests/_ast/codegen_data/test_generate_filecontents_async.py
index 20d6633c18..9b325a3bc0 100644
--- a/tests/_ast/codegen_data/test_generate_filecontents_async.py
+++ b/tests/_ast/codegen_data/test_generate_filecontents_async.py
@@ -8,7 +8,7 @@ app = marimo.App()
def one():
import numpy as np
import asyncio
- return asyncio, np
+ return (asyncio,)
@app.cell
@@ -16,7 +16,7 @@ async def two(asyncio):
x = 0
xx = 1
await asyncio.sleep(1)
- return x, xx
+ return (x,)
@app.cell
diff --git a/tests/_ast/codegen_data/test_generate_filecontents_async_long_signature.py b/tests/_ast/codegen_data/test_generate_filecontents_async_long_signature.py
index d4c49fec89..55970d0843 100644
--- a/tests/_ast/codegen_data/test_generate_filecontents_async_long_signature.py
+++ b/tests/_ast/codegen_data/test_generate_filecontents_async_long_signature.py
@@ -40,7 +40,7 @@ async def two(
async for data_point in client("test", "ws://localhost:8000"):
print(data_point)
data_point
- return (data_point,)
+ return
if __name__ == "__main__":
diff --git a/tests/_ast/codegen_data/test_generate_filecontents_single_cell.py b/tests/_ast/codegen_data/test_generate_filecontents_single_cell.py
index 0152a08112..c31ea72399 100644
--- a/tests/_ast/codegen_data/test_generate_filecontents_single_cell.py
+++ b/tests/_ast/codegen_data/test_generate_filecontents_single_cell.py
@@ -7,7 +7,7 @@ app = marimo.App()
@app.cell
def one():
import numpy as np
- return (np,)
+ return
if __name__ == "__main__":
diff --git a/tests/_ast/codegen_data/test_generate_filecontents_with_syntax_error.py b/tests/_ast/codegen_data/test_generate_filecontents_with_syntax_error.py
index 6a7972aade..56f41dba5a 100644
--- a/tests/_ast/codegen_data/test_generate_filecontents_with_syntax_error.py
+++ b/tests/_ast/codegen_data/test_generate_filecontents_with_syntax_error.py
@@ -7,7 +7,7 @@ app = marimo.App()
@app.cell
def one():
import numpy as np
- return (np,)
+ return
app._unparsable_cell(
diff --git a/tests/_ast/codegen_data/test_long_line_in_main.py b/tests/_ast/codegen_data/test_long_line_in_main.py
index 823da962c9..3fb2e103c0 100644
--- a/tests/_ast/codegen_data/test_long_line_in_main.py
+++ b/tests/_ast/codegen_data/test_long_line_in_main.py
@@ -23,7 +23,7 @@ def two(
yet_another_very_long_name,
):
z = i_am_a_very_long_name + i_am_another_very_long_name + yet_another_very_long_name
- return (z,)
+ return
if __name__ == "__main__":
diff --git a/tests/_ast/test_codegen.py b/tests/_ast/test_codegen.py
index 8016273f9a..2b2a34c57a 100644
--- a/tests/_ast/test_codegen.py
+++ b/tests/_ast/test_codegen.py
@@ -79,7 +79,6 @@ def get_idempotent_marimo_source(name: str) -> str:
list(app._cell_manager.configs()),
app._config,
header_comments,
- _toplevel_fn=True,
)
generated_contents = sanitized_version(generated_contents)
diff --git a/tests/_cli/snapshots/converted_multiple_defs.py.txt b/tests/_cli/snapshots/converted_multiple_defs.py.txt
index 1f1ea640ab..173443fdeb 100644
--- a/tests/_cli/snapshots/converted_multiple_defs.py.txt
+++ b/tests/_cli/snapshots/converted_multiple_defs.py.txt
@@ -20,7 +20,7 @@ def _():
@app.cell
def _():
y = 0
- return (y,)
+ return
@app.cell
diff --git a/tests/_convert/test_convert_utils.py b/tests/_convert/test_convert_utils.py
index fcb724edb2..93906800a9 100644
--- a/tests/_convert/test_convert_utils.py
+++ b/tests/_convert/test_convert_utils.py
@@ -46,7 +46,7 @@ def _():
@app.cell
def _():
x = 5
- return (x,)
+ return
if __name__ == "__main__":
@@ -79,7 +79,7 @@ def _():
@app.cell
def _():
x = 5
- return (x,)
+ return
if __name__ == "__main__":
diff --git a/tests/_server/test_file_manager.py b/tests/_server/test_file_manager.py
index 603ae439d6..ad63161718 100644
--- a/tests/_server/test_file_manager.py
+++ b/tests/_server/test_file_manager.py
@@ -246,7 +246,7 @@ def test_to_code(app_file_manager: AppFileManager) -> None:
"@app.cell",
"def _():",
" import marimo as mo",
- " return (mo,)",
+ " return",
"",
"",
'if __name__ == "__main__":',