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.

fix: trim `return` for ruff formatting (#11430)

Dylan Madisettia61726dcda47
diff --git a/marimo/_ast/codegen.py b/marimo/_ast/codegen.py
index 68e58a4305..d7645635ac 100644
--- a/marimo/_ast/codegen.py
+++ b/marimo/_ast/codegen.py
@@ -158,6 +158,24 @@ def _needs_trailing_blank_line(mod: ast.Module, code: str) -> bool:
return last_stmt.end_lineno == code_lines
+def _can_strip_bare_return(cell: CellImpl) -> bool:
+ """Returns True if a bare return can be safely omitted (ruff-compatible)."""
+ # Comment only case
+ if not cell.mod.body:
+ return False
+ # If the user has explicit \n, then we leave it
+ if cell.code.rstrip(" \t") != cell.code.rstrip(" \t\r\n"):
+ return False
+ # A single function/class def would trigger toplevel reclassification
+ return not (
+ len(cell.mod.body) == 1
+ and isinstance(
+ cell.mod.body[0],
+ (ast.FunctionDef, ast.AsyncFunctionDef, ast.ClassDef),
+ )
+ )
+
+
def to_decorator(
config: CellConfig | None,
fn: Decorators = "cell",
@@ -375,19 +393,20 @@ def to_functiondef(
elif body := indent_text(cell.code):
definition_body.append(body)
- returns = format_tuple_elements(
- "return (...)",
- defs,
- indent=True,
- allowed_naked=True,
- # maybe consider "return Edges(...)"
- # Such that the return type can simply be 'Edges'
- )
- # Add blank line before return for ruff compatibility when last statement
- # is an import, function def, or class def
- if _needs_trailing_blank_line(cell.mod, cell.code):
- definition_body.append("")
- definition_body.append(returns)
+ if defs or not _can_strip_bare_return(cell):
+ returns = format_tuple_elements(
+ "return (...)",
+ defs,
+ indent=True,
+ allowed_naked=True,
+ # maybe consider "return Edges(...)"
+ # Such that the return type can simply be 'Edges'
+ )
+ # Add blank line before return for ruff compatibility when last statement
+ # is an import, function def, or class def
+ if _needs_trailing_blank_line(cell.mod, cell.code):
+ definition_body.append("")
+ definition_body.append(returns)
return "\n".join(definition_body)
diff --git a/marimo/_cli/development/commands.py b/marimo/_cli/development/commands.py
index f2ebbc42bd..64946e681f 100644
--- a/marimo/_cli/development/commands.py
+++ b/marimo/_cli/development/commands.py
@@ -232,7 +232,6 @@ def print_routes() -> None:
print_all_routes(route.app, new_base_path)
print_all_routes(app)
- return
@click.command(cls=ColoredCommand, help="Preview a marimo file as static HTML")
diff --git a/marimo/_cli/export/commands.py b/marimo/_cli/export/commands.py
index 2c5a2d325a..5a85858d89 100644
--- a/marimo/_cli/export/commands.py
+++ b/marimo/_cli/export/commands.py
@@ -172,7 +172,6 @@ def watch_and_export(
output.write_bytes(result.bytez)
else:
echo(result.text)
- return
if output:
output_path = Path(output)
diff --git a/marimo/_output/md.py b/marimo/_output/md.py
index 7c2bf047f3..8c384014f7 100644
--- a/marimo/_output/md.py
+++ b/marimo/_output/md.py
@@ -444,4 +444,3 @@ def latex(
# Append the LaTeX to the output, in case this
# is not the last expression of the cell
output.append(_md(f"$$\n{latex_text.strip()}\n$$"))
- return
diff --git a/marimo/_runtime/context/script_context.py b/marimo/_runtime/context/script_context.py
index be331cd024..bcad5eb3ce 100644
--- a/marimo/_runtime/context/script_context.py
+++ b/marimo/_runtime/context/script_context.py
@@ -112,7 +112,6 @@ class ScriptRuntimeContext(RuntimeContext):
def register_state_update(self, state: State[Any]) -> None:
del state
- return
@contextmanager
def with_cell_id(self, cell_id: CellId_t) -> Iterator[None]:
diff --git a/marimo/_runtime/kernel_request_handlers.py b/marimo/_runtime/kernel_request_handlers.py
index 758669e0b3..d614d31a45 100644
--- a/marimo/_runtime/kernel_request_handlers.py
+++ b/marimo/_runtime/kernel_request_handlers.py
@@ -278,4 +278,3 @@ class KernelRequestHandlers:
async def _handle_stop(self, request: StopKernelCommand) -> None:
del request
- return
diff --git a/marimo/_session/events.py b/marimo/_session/events.py
index 80124d6010..f04fd164ee 100644
--- a/marimo/_session/events.py
+++ b/marimo/_session/events.py
@@ -30,12 +30,10 @@ class SessionEventListener:
async def on_session_created(self, session: Session) -> None:
"""Called when a session is created."""
del session
- return
async def on_session_closed(self, session: Session) -> None:
"""Called when a session is closed."""
del session
- return
async def on_session_resumed(
self, session: Session, old_id: SessionId
@@ -43,7 +41,6 @@ class SessionEventListener:
"""Called when a session is resumed with a new ID."""
del session
del old_id
- return
async def on_session_notebook_renamed(
self, session: Session, old_path: str | None
@@ -51,7 +48,6 @@ class SessionEventListener:
"""Called when a session notebook is renamed."""
del session
del old_path
- return
def on_notification_sent(
self, session: Session, notification: KernelMessage
@@ -59,7 +55,6 @@ class SessionEventListener:
"""Called before a session notification is broadcast to consumers."""
del session
del notification
- return
def on_received_command(
self,
@@ -71,13 +66,11 @@ class SessionEventListener:
del session
del request
del from_consumer_id
- return
def on_received_stdin(self, session: Session, stdin: str) -> None:
"""Called when stdin is received."""
del session
del stdin
- return
class SessionEventBus:
diff --git a/marimo/_tutorials/dataflow.py b/marimo/_tutorials/dataflow.py
index 485dfc7eaa..16922e237b 100644
--- a/marimo/_tutorials/dataflow.py
+++ b/marimo/_tutorials/dataflow.py
@@ -10,7 +10,7 @@
import marimo
-__generated_with = "0.23.6"
+__generated_with = "0.25.2"
app = marimo.App()
@@ -26,7 +26,6 @@ def _(mo):
To provide reactive execution, marimo creates a dataflow graph out of your
cells.
""")
- return
@app.cell(hide_code=True)
@@ -42,7 +41,6 @@ def _(mo):
runtime puts you in control over when cells are run, while still giving
guarantees about the notebook state.
""")
- return
@app.cell(hide_code=True)
@@ -63,7 +61,6 @@ def _(mo):
The rule for reactive execution can be restated in terms of the graph: when
a cell is run, its descendants are run automatically.
""")
- return
@app.cell(hide_code=True)
@@ -74,7 +71,6 @@ def _(mo):
The next four cells plot a sine wave with a given period and amplitude.
Each cell is labeled with its refs and defs.
""")
- return
@app.cell(hide_code=True)
@@ -91,7 +87,6 @@ def _(mo):
"""
}
)
- return
@app.cell
@@ -102,7 +97,6 @@ def _(amplitude, mo, period, plot_wave):
- `refs: {mo.refs()}`
- `defs: {mo.defs()}`
""")
- return
@app.cell
@@ -162,7 +156,6 @@ def _(mo):
`amplitude`, then click the run button ( ▷ ) to register your changes.
See what happens to the sine wave.
""")
- return
@app.cell(hide_code=True)
@@ -190,7 +183,6 @@ def _(mo):
The last cell, which doesn't define anything, produces the plot.
""")
- return
@app.cell(hide_code=True)
@@ -202,7 +194,6 @@ def _(mo):
surprising if you are not used to dataflow programming. We list these
below.
""")
- return
@app.cell(hide_code=True)
@@ -215,7 +206,6 @@ def _(mo):
traditional notebooks. It also lets you place boilerplate, like
imports or long markdown strings, at the bottom of the editor.
""")
- return
@app.cell(hide_code=True)
@@ -230,21 +220,18 @@ def _(mo):
If you violate this constraint, marimo provides a helpful
error message, like below:
""")
- return
@app.cell
def _():
planet = "Mars"
planet
- return
@app.cell
def _():
planet = "Earth"
planet
- return
@app.cell(hide_code=True)
@@ -253,7 +240,6 @@ def _(mo):
**🌊 Try it!** In the previous cell, change the name `planet` to `home`,
then run the cell.
""")
- return
@app.cell(hide_code=True)
@@ -266,19 +252,16 @@ def _(mo):
**🌊 Try it!** Get rid of the following errors by merging the next two
cells into a single cell.
""")
- return
@app.cell
def _():
count = 0
- return
@app.cell
def _():
count += 1
- return
@app.cell(hide_code=True)
@@ -293,28 +276,24 @@ def _(mo):
**Example**.
""")
- return
@app.cell
def _():
_private_variable, _ = 1, 2
_private_variable, _
- return
@app.cell
def _():
_private_variable, _ = 3, 4
_private_variable, _
- return
@app.cell
def _():
# `_private_variable` and `_` are not defined in this cell
_private_variable, _
- return
@app.cell(hide_code=True)
@@ -327,7 +306,6 @@ def _(mo):
can arise when state has been deleted from the editor but not from the
program memory.
""")
- return
@app.cell
@@ -347,7 +325,6 @@ def _(mo):
@app.cell
def _(to_be_deleted):
to_be_deleted
- return
@app.cell(hide_code=True)
@@ -357,7 +334,6 @@ def _(mo):
Cycles among cells are not allowed. For example:
""")
- return
@app.cell
@@ -383,19 +359,16 @@ def _(mo):
**🌊 Example**. Change the value of `state.number` in the next cell, then
run the cell. Notice how the subsequent cell isn't updated.
""")
- return
@app.cell
def _(state):
state.number = 1
- return
@app.cell
def _(state):
state.number
- return
@app.cell
@@ -419,7 +392,6 @@ def _(mo):
"""
}
)
- return
@app.cell(hide_code=True)
@@ -431,7 +403,6 @@ def _(mo):
mutate an object without running it. So: mutations (such as
appending to a list) will not trigger reactive execution.
""")
- return
@app.cell(hide_code=True)
@@ -447,7 +418,6 @@ def _(mo):
)
}
)
- return
@app.cell(hide_code=True)
@@ -465,13 +435,11 @@ def _(mo):
Follow these tips to stay on the marimo way:
""")
- return
@app.cell
def _(mo, tips):
mo.accordion(tips)
- return
@app.cell(hide_code=True)
@@ -485,7 +453,6 @@ def _(mo):
marimo tutorial ui
```
""")
- return
@app.cell
diff --git a/marimo/_tutorials/external_dependencies.py b/marimo/_tutorials/external_dependencies.py
index 8ac02d8f7d..7d4c8ba947 100644
--- a/marimo/_tutorials/external_dependencies.py
+++ b/marimo/_tutorials/external_dependencies.py
@@ -9,7 +9,7 @@
import marimo
-__generated_with = "0.23.6"
+__generated_with = "0.25.2"
app = marimo.App()
@@ -23,13 +23,11 @@ def _(mo):
[PEP 723](https://peps.python.org/pep-0723/) inline metadata, to declare
the Python version and packages that a notebook needs.
""")
- return
@app.cell(hide_code=True)
def _(check_dependencies):
check_dependencies()
- return
@app.cell(hide_code=True)
@@ -51,7 +49,6 @@ def _(mo):
environment with the right dependencies. The rest of the file remains a
regular Python script.
""")
- return
@app.cell(hide_code=True)
@@ -62,7 +59,6 @@ def _(mo):
Here we'll use `wigglystuff.Slider2D`, an anywidget, and wrap it with
`mo.ui.anywidget` so marimo can make it reactive.
""")
- return
@app.cell
@@ -89,7 +85,6 @@ def _(mo, widget):
f"x = {widget.x:.3f}, y = {widget.y:.3f}; "
f"bounds {widget.x_bounds} / {widget.y_bounds}"
)
- return
@app.cell(hide_code=True)
diff --git a/marimo/_tutorials/fileformat.py b/marimo/_tutorials/fileformat.py
index 908f69a949..fcb810fc1c 100644
--- a/marimo/_tutorials/fileformat.py
+++ b/marimo/_tutorials/fileformat.py
@@ -8,7 +8,7 @@
import marimo
-__generated_with = "0.19.7"
+__generated_with = "0.25.2"
app = marimo.App()
with app.setup:
@@ -38,7 +38,6 @@ def _(mo):
- 🐍 usable as Python scripts, with UI elements taking their default values
- 🧩 modular, exposing functions and classes that can be imported from the notebook
""")
- return
@app.cell(hide_code=True)
@@ -70,7 +69,6 @@ def _(mo):
import marimo as mo
```
""")
- return
@app.cell(hide_code=True)
@@ -116,7 +114,6 @@ def _(mo):
Moreover, the cell defining a single pure function `say_hello` was saved "top-level" in the notebook file, making it possible for you to import it into other Python files or notebooks.
""")
- return
@app.cell(hide_code=True)
@@ -131,7 +128,6 @@ def _(mo):
We explain some properties of marimo's file format below.
""")
- return
@app.cell(hide_code=True)
@@ -241,7 +237,6 @@ def _(mo):
""",
}
)
- return
@app.cell(hide_code=True)
@@ -253,7 +248,6 @@ def _(mo):
functions and classes defined in your notebook into other Python modules. If you
don't intend to do so, you can skip this section.
""")
- return
@app.cell(hide_code=True)
@@ -284,7 +278,6 @@ def _(mo):
classes. You can add the setup cell from the general menu of the editor under:
::lucide:diamond-plus:: Add setup cell.
""")
- return
@app.cell(hide_code=True)
@@ -294,7 +287,6 @@ def _(mo):
Notebook files expose functions and classes that depend only on variables defined in the setup cell (or on other such functions or classes). For example, the following cell:
""")
- return
@app.function
@@ -330,7 +322,6 @@ def _(mo):
from my_notebook import roll_die
```
""")
- return
@app.cell(hide_code=True)
@@ -338,7 +329,6 @@ def _(mo):
mo.md(r"""
Standalone classes are also exposed:
""")
- return
@app.class_definition
@@ -365,7 +355,6 @@ def _(mo):
return [roll_die() for _ in range(self.n_rolls)]
```
""")
- return
@app.cell(hide_code=True)
@@ -381,7 +370,6 @@ def _(mo):
For example, this function will not be exposed:
""")
- return
@app.cell
@@ -422,7 +410,6 @@ def _(mo):
See the docs on [testing](https://docs.marimo.io/guides/testing/).
""")
- return
@app.cell(hide_code=True)
@@ -432,7 +419,6 @@ def _(mo):
The source code of this notebook is shown below:
""")
- return
@app.cell
@@ -445,7 +431,6 @@ def _():
@app.cell
def _(contents, mo):
mo.ui.code_editor(contents)
- return
if __name__ == "__main__":
diff --git a/marimo/_tutorials/for_jupyter_users.py b/marimo/_tutorials/for_jupyter_users.py
index 03cdaf91a7..7043185b2f 100644
--- a/marimo/_tutorials/for_jupyter_users.py
+++ b/marimo/_tutorials/for_jupyter_users.py
@@ -8,7 +8,7 @@
import marimo
-__generated_with = "0.23.6"
+__generated_with = "0.25.2"
app = marimo.App(app_title="marimo for Jupyter users")
@@ -20,7 +20,6 @@ def _(mo):
This notebook explains important differences between Jupyter and marimo. If you're
familiar with Jupyter and are trying out marimo for the first time, read on!
""")
- return
@app.cell(hide_code=True)
@@ -32,7 +31,6 @@ def _(mo):
Try updating the value of x in the next cell, then run it.
""")
- return
@app.cell
@@ -44,7 +42,6 @@ def _():
@app.cell
def _(x):
y = x + 1; y
- return
@app.cell(hide_code=True)
@@ -59,7 +56,6 @@ def _(mo):
In contrast, Jupyter requires you to manually run each cell.
""")
- return
@app.cell(hide_code=True)
@@ -77,7 +73,6 @@ def _(mo):
This makes marimo notebooks as reproducible as regular Python scripts.
""")
- return
@app.cell(hide_code=True)
@@ -88,7 +83,6 @@ def _(mo):
marimo comes with a [large library of UI elements](https://docs.marimo.io/guides/interactivity.html) that are automatically
synchronized with Python.
""")
- return
@app.cell
@@ -108,7 +102,6 @@ def _(mo):
@app.cell
def _(slider):
slider.value
- return
@app.cell(hide_code=True)
@@ -123,7 +116,6 @@ def _(mo):
In contrast, Jupyter's lack of reactivity makes IPyWidgets difficult to use.
""")
- return
@app.cell(hide_code=True)
@@ -141,7 +133,6 @@ def _(mo):
seamless to do so if you want to. In this way, marimo works as a replacement
for both Jupyter and Streamlit.
""")
- return
@app.cell(hide_code=True)
@@ -151,13 +142,11 @@ def _(mo):
In marimo, cells can be arranged in any order — marimo figures out the one true way to execute them based on variable declarations and references (in a ["topologically sorted"](https://en.wikipedia.org/wiki/Topological_sorting#:~:text=In%20computer%20science%2C%20a%20topological,before%20v%20in%20the%20ordering.) order)
""")
- return
@app.cell
def _(z):
z.value
- return
@app.cell
@@ -173,7 +162,6 @@ def _(mo):
In contrast, Jupyter notebooks implicitly assume a top-to-bottom execution order.
""")
- return
@app.cell(hide_code=True)
@@ -183,7 +171,6 @@ def _(mo):
marimo disallows variable re-assignment. Here is something commonly done in Jupyter notebooks that cannot be done in marimo:
""")
- return
@app.cell
@@ -201,7 +188,6 @@ def _():
@app.cell
def _(df):
results = df.groupby(["my_column"]).sum()
- return
@app.cell(hide_code=True)
@@ -215,7 +201,6 @@ def _(mo):
2. prefix variables with an underscore (`_df`) to make them local to the cell
3. wrap your code in functions, or give your variables more descriptive names
""")
- return
@app.cell(hide_code=True)
@@ -233,7 +218,6 @@ def _(mo):
ergonomics for authoring.
///
""")
- return
@app.cell
@@ -241,7 +225,6 @@ def _(mo, slider):
mo.md(f"""
The value of {slider} is {slider.value}.
""")
- return
@app.cell(hide_code=True)
@@ -254,7 +237,6 @@ def _(mo):
_Tip: toggle a markdown view via `Cmd/Ctrl-Shift-M` in an empty cell._
""")
- return
@app.cell(hide_code=True)
@@ -274,7 +256,6 @@ def _(mo):
marimo is designed so that small changes in your code yield small git diffs!
""")
- return
@app.cell(hide_code=True)
@@ -293,7 +274,6 @@ def _(mo):
users](https://featured.plutojl.org/basic/pluto%20for%20jupyter%20users).
We ❤️ Pluto.jl!_
""")
- return
if __name__ == "__main__":
diff --git a/marimo/_tutorials/intro.py b/marimo/_tutorials/intro.py
index 17056ee2a2..be88908aee 100644
--- a/marimo/_tutorials/intro.py
+++ b/marimo/_tutorials/intro.py
@@ -8,7 +8,7 @@
import marimo
-__generated_with = "0.23.15"
+__generated_with = "0.25.2"
app = marimo.App()
@@ -37,7 +37,6 @@ def _(mo, slider):
{"##" + "🍃" * slider.value}
""")
- return
@app.cell(hide_code=True)
@@ -57,7 +56,6 @@ def _(mo):
)
}
)
- return
@app.cell(hide_code=True)
@@ -68,7 +66,6 @@ def _(mo):
with `marimo edit` at the command line.
"""
).callout(kind="info", title="Creating your own notebooks")
- return
@app.cell(hide_code=True)
@@ -87,7 +84,6 @@ def _(mo):
making for a dynamic programming environment that prevents bugs before they
happen.
""")
- return
@app.cell(hide_code=True)
@@ -114,7 +110,6 @@ def _(changed, mo):
"""
)
)
- return
@app.cell
@@ -138,7 +133,6 @@ def _(mo):
)
}
)
- return
@app.cell(hide_code=True)
@@ -148,7 +142,6 @@ def _(mo):
constraint on how names appear in cells: no two cells may define the same
variable.
""")
- return
@app.cell(hide_code=True)
@@ -163,7 +156,6 @@ def _(mo):
)
}
)
- return
@app.cell(hide_code=True)
@@ -178,7 +170,6 @@ def _(mo):
)
}
)
- return
@app.cell(hide_code=True)
@@ -194,7 +185,6 @@ def _(mo):
marimo provides a library of UI elements to choose from under
`marimo.ui`.
""")
- return
@app.cell
@@ -202,7 +192,6 @@ def _(mo):
mo.md("""
**🌊 Some UI elements.** Try interacting with the below elements.
""")
- return
@app.cell
@@ -220,13 +209,11 @@ def _(icon, mo):
@app.cell
def _(icon, repetitions):
icon, repetitions
- return
@app.cell
def _(icon, mo, repetitions):
mo.md("# " + icon.value * repetitions.value)
- return
@app.cell(hide_code=True)
@@ -247,7 +234,6 @@ def _(mo):
values, and
- importable by other modules (more on that in the future).
""")
- return
@app.cell(hide_code=True)
@@ -262,7 +248,6 @@ def _(mo):
Of course, you can use marimo just to level-up your
notebooking, without ever making apps.
""")
- return
@app.cell(hide_code=True)
@@ -319,7 +304,6 @@ def _(mo):
In addition to tutorials, we have examples in
[our GitHub repo](https://www.github.com/marimo-team/marimo/tree/main/examples).
""")
- return
@app.cell(hide_code=True)
@@ -329,13 +313,11 @@ def _(mo):
Here are some tips to help you get started with the marimo editor.
""")
- return
@app.cell
def _(mo, tips):
mo.accordion(tips)
- return
@app.cell(hide_code=True)
@@ -343,7 +325,6 @@ def _(mo):
mo.md("""
## Finally, a fun fact
""")
- return
@app.cell(hide_code=True)
@@ -354,7 +335,6 @@ def _(mo):
called a "marimo moss ball". Made of just strands of algae, these
beloved assemblages are greater than the sum of their parts.
""")
- return
@app.cell(hide_code=True)
diff --git a/marimo/_tutorials/layout.py b/marimo/_tutorials/layout.py
index 2dc0ec8149..1842d734ce 100644
--- a/marimo/_tutorials/layout.py
+++ b/marimo/_tutorials/layout.py
@@ -8,7 +8,7 @@
import marimo
-__generated_with = "0.23.15"
+__generated_with = "0.25.2"
app = marimo.App()
@@ -20,7 +20,6 @@ def _(mo):
`marimo` provides functions to help you lay out your output, such as
in rows and columns, accordions, tabs, and callouts.
""")
- return
@app.cell(hide_code=True)
@@ -30,7 +29,6 @@ def _(mo):
Arrange objects into rows and columns with `mo.hstack` and `mo.vstack`.
""")
- return
@app.cell
@@ -39,13 +37,11 @@ def _(mo):
[mo.ui.text(label="hello"), mo.ui.slider(1, 10, label="slider")],
justify="start",
)
- return
@app.cell
def _(mo):
mo.vstack([mo.ui.text(label="world"), mo.ui.number(1, 10, label="number")])
- return
@app.cell
@@ -71,7 +67,6 @@ def _(mo):
plots!).
"""
)
- return
@app.cell(hide_code=True)
@@ -81,7 +76,6 @@ def _(mo):
The presentation of stacked elements can be customized with some arguments
that are best understood by example.
""")
- return
@app.cell
@@ -117,7 +111,6 @@ def _(align, boxes, gap, justify, mo, wrap):
gap=gap.value,
wrap=wrap.value,
)
- return
@app.cell
@@ -127,7 +120,6 @@ def _(align, boxes, gap, mo):
align=align.value,
gap=gap.value,
)
- return
@app.cell
@@ -151,7 +143,6 @@ def _(mo):
"Documentation: `mo.vstack`": mo.doc(mo.vstack),
}
)
- return
@app.cell(hide_code=True)
@@ -162,7 +153,6 @@ def _(mo):
functions, and subclassed by most marimo classes) have a shortcut using
via their `center`, `right`, and `left` methods.
""")
- return
@app.cell
@@ -170,19 +160,16 @@ def _(mo):
mo.md("""
This markdown is left-justified.
""")
- return
@app.cell
def _(mo):
mo.md("This markdown is centered.").center()
- return
@app.cell
def _(mo):
mo.md("This markdown is right-justified.").right()
- return
@app.cell(hide_code=True)
@@ -194,7 +181,6 @@ def _(mo):
"Documentation: `Html.left`": mo.doc(mo.Html.left),
}
)
- return
@app.cell(hide_code=True)
@@ -204,7 +190,6 @@ def _(mo):
Create expandable shelves of content using `mo.accordion`:
""")
- return
@app.cell(hide_code=True)
@@ -212,7 +197,6 @@ def _(mo):
mo.md("""
An accordion can contain multiple items:
""")
- return
@app.cell
@@ -228,7 +212,6 @@ def _(mo):
),
}
)
- return
@app.cell(hide_code=True)
@@ -238,7 +221,6 @@ def _(mo):
Use `mo.ui.tabs` to display multiple objects in a single tabbed output:
""")
- return
@app.cell
@@ -265,13 +247,11 @@ def _(mo):
"🏢 Organization": _organization,
}
)
- return
@app.cell(hide_code=True)
def _(mo):
mo.accordion({"Documentation: `mo.ui.tabs`": mo.doc(mo.ui.tabs)})
- return
@app.cell
@@ -292,13 +272,11 @@ def _(mo):
{mo.tree(_t)}
"""
)
- return
@app.cell(hide_code=True)
def _(mo):
mo.accordion({"Documentation: `mo.tree`": mo.doc(mo.tree)})
- return
@app.cell(hide_code=True)
@@ -309,7 +287,6 @@ def _(mo):
Turn any markdown or HTML into an emphasized callout with the `callout`
method:
""")
- return
@app.cell
@@ -329,13 +306,11 @@ def _(callout_kind, mo):
{callout_kind}
"""
).callout(kind=callout_kind.value, title="This is a callout!")
- return
@app.cell(hide_code=True)
def _(mo):
mo.accordion({"Documentation: `mo.callout`": mo.doc(mo.callout)})
- return
@app.cell
diff --git a/marimo/_tutorials/markdown.py b/marimo/_tutorials/markdown.py
index 123056eb7e..e41f090334 100644
--- a/marimo/_tutorials/markdown.py
+++ b/marimo/_tutorials/markdown.py
@@ -11,7 +11,7 @@
import marimo
-__generated_with = "0.23.15"
+__generated_with = "0.25.2"
app = marimo.App()
@@ -37,7 +37,6 @@ def _(mo):
)
```
""")
- return
@app.cell
@@ -57,7 +56,6 @@ def _(mo):
a Python f-string; do this by checking the `f` box in the bottom-right corner of the
markdown editor, or with `mo.md(f"...")` in the Python view.
""")
- return
@app.cell(hide_code=True)
@@ -74,7 +72,6 @@ def _(mo):
Supported kinds include Note, Tip, Hint, Important, Warning, and Danger.
///
""")
- return
@app.cell(hide_code=True)
@@ -107,7 +104,6 @@ def _(mo):
f: \mathbf{R} \to \mathbf{R}.
$$
""")
- return
@app.cell(hide_code=True)
@@ -117,7 +113,6 @@ def _(mo):
Use `r''` strings to remove the need to escape backslashes when writing LaTeX.
///
""")
- return
@app.cell(hide_code=True)
@@ -130,7 +125,6 @@ def _(mo):
https://katex.org/docs/support_table
///
""")
- return
@app.cell(hide_code=True)
@@ -144,7 +138,6 @@ def _(mo):
Here are some examples.
""")
- return
@app.cell
@@ -169,7 +162,6 @@ def _(mo, np, plt):
{mo.as_html(_sine_plot())}
"""
)
- return
@app.cell
@@ -200,7 +192,6 @@ def _(leaves, mo):
mo.md(f"""
Your leaves: {"🍃" * leaves.value}
""")
- return
@app.cell(hide_code=True)
@@ -213,7 +204,6 @@ def _(mo):
"""
}
)
- return
@app.cell
@@ -243,7 +233,6 @@ def _(mo, np):
{mo.as_html(make_dataframe())}
"""
)
- return
@app.cell(hide_code=True)
@@ -257,7 +246,6 @@ def _(mo):
"""
}
)
- return
@app.cell(hide_code=True)
@@ -269,7 +257,6 @@ def _(mo):
everything we've learned: rendering markdown with LaTeX that depends on
the values of Python objects.
""")
- return
@app.cell
@@ -305,7 +292,6 @@ def _(amplitude, mo, period):
- {amplitude}
- {period}
""")
- return
@app.cell
@@ -320,7 +306,6 @@ def _(amplitude, mo, period, plotsin):
with $x$ ranging from $0$ to $2\pi$.
{mo.as_html(plotsin(amplitude.value, period.value))}
""")
- return
@app.cell(hide_code=True)
diff --git a/marimo/_tutorials/plots.py b/marimo/_tutorials/plots.py
index 5770bba1c3..f0423d87b5 100644
--- a/marimo/_tutorials/plots.py
+++ b/marimo/_tutorials/plots.py
@@ -10,7 +10,7 @@
import marimo
-__generated_with = "0.23.6"
+__generated_with = "0.25.2"
app = marimo.App()
@@ -19,13 +19,11 @@ def _(mo):
mo.md("""
# Plotting
""")
- return
@app.cell(hide_code=True)
def _(check_dependencies):
check_dependencies()
- return
@app.cell(hide_code=True)
@@ -37,7 +35,6 @@ def _(mo):
This tutorial gives examples using matplotlib; other libraries are
used similarly.
""")
- return
@app.cell(hide_code=True)
@@ -45,7 +42,6 @@ def _(mo):
mo.md("""
## Matplotlib
""")
- return
@app.cell(hide_code=True)
@@ -60,13 +56,11 @@ def _(mo):
plt.plot([1, 2])
```
""")
- return
@app.cell
def _(plt):
plt.plot([1, 2])
- return
@app.cell(hide_code=True)
@@ -80,7 +74,6 @@ def _(mo):
plt.gca()
```
""")
- return
@app.cell
@@ -89,13 +82,11 @@ def _(plt):
# ... do some work ...
# make plt.gca() the last line of the cell
plt.gca()
- return
@app.cell(hide_code=True)
def _(mo, plt_show_explainer):
mo.accordion(plt_show_explainer)
- return
@app.cell(hide_code=True)
@@ -104,7 +95,6 @@ def _(mo):
**A new figure every cell.** Every cell starts with an empty figure for
the imperative `pyplot` API.
""")
- return
@app.cell
@@ -118,13 +108,11 @@ def _(plt, x):
plt.plot(x, x)
plt.plot(x, x**2)
plt.gca()
- return
@app.cell
def _(plt, x):
plt.plot(x, x**3)
- return
@app.cell(hide_code=True)
@@ -133,7 +121,6 @@ def _(mo):
To build a figure over multiple cells, use the object-oriented API and
create your own axis:
""")
- return
@app.cell
@@ -149,7 +136,6 @@ def _(plt, x):
def _(axis, x):
axis.plot(x, x**3)
axis
- return
@app.cell(hide_code=True)
@@ -159,7 +145,6 @@ def _(mo):
Draw plots interactively by parametrizing them with UI elements.
""")
- return
@app.cell
@@ -200,7 +185,6 @@ def _(exponent, mo, plot_power):
{mo.as_html(plot_power(exponent.value))}
"""
)
- return
@app.cell(hide_code=True)
@@ -213,7 +197,6 @@ def _(mo):
(shift-drag). Use `fig.value.get_mask(x, y)` to get a boolean mask
of the selected points.
""")
- return
@app.cell
@@ -229,7 +212,6 @@ def _(mo, np, plt):
def _(XY, scatter_fig):
_mask = scatter_fig.value.get_mask(XY[:, 0], XY[:, 1])
XY[_mask]
- return
@app.cell(hide_code=True)
@@ -237,7 +219,6 @@ def _(mo):
mo.md("""
## Other libraries
""")
- return
@app.cell(hide_code=True)
@@ -255,7 +236,6 @@ def _(mo):
If you would like another library to be integrated into marimo, please
get in touch.
""")
- return
@app.cell(hide_code=True)
diff --git a/marimo/_tutorials/sql.py b/marimo/_tutorials/sql.py
index 717ea3a243..25287152c3 100644
--- a/marimo/_tutorials/sql.py
+++ b/marimo/_tutorials/sql.py
@@ -16,7 +16,7 @@
import marimo
-__generated_with = "0.19.7"
+__generated_with = "0.25.2"
app = marimo.App(width="medium")
@@ -27,7 +27,6 @@ def _(mo):
_Let's dive into the world of SQL where we don't just address tables, we also join them!_
""")
- return
@app.cell(hide_code=True)
@@ -41,7 +40,6 @@ def _(mo):
pip install 'marimo[sql]'
```
""")
- return
@app.cell(hide_code=True)
@@ -95,7 +93,6 @@ def _(has_duckdb_installed, mo):
"""
)
)
- return
@app.cell(hide_code=True)
@@ -128,7 +125,6 @@ def _(mo):
means it can contain any valid Python code, such as the values of UI
elements. This means your SQL statement and results can be reactive! 🚀
""")
- return
@app.cell(hide_code=True)
@@ -136,7 +132,6 @@ def _(mo):
mo.md("""
## Querying dataframes with SQL
""")
- return
@app.cell(hide_code=True)
@@ -148,7 +143,6 @@ def _(mo):
and in-memory tables that your notebook has access to.
///
""")
- return
@app.cell(hide_code=True)
@@ -156,7 +150,6 @@ def _(mo):
mo.md(r"""
Let's take a look at a SQL cell. The next cell generates a dataframe called `df`.
""")
- return
@app.cell(hide_code=True)
@@ -207,7 +200,6 @@ def _(mo):
mo.md(r"""
Next, we create a SQL query, referencing the Python dataframe `df` directly.
""")
- return
@app.cell
@@ -221,7 +213,6 @@ def _(df, mo):
-- By default, the output variable starts with an underscore (`_df`), making it private to this cell. To access the query result in another cell, change the name of the output variable.
"""
)
- return
@app.cell(hide_code=True)
@@ -229,7 +220,6 @@ def _(mo):
mo.md("""
## From Python to SQL and back
""")
- return
@app.cell(hide_code=True)
@@ -237,7 +227,6 @@ def _(mo):
mo.md(r"""
You can create SQL statements that depend on Python values, such as UI elements:
""")
- return
@app.cell(hide_code=True)
@@ -270,7 +259,6 @@ def _(mo):
Since we named the output variable above **`result`**,
we can use it back in Python.
""")
- return
@app.cell(hide_code=True)
@@ -301,7 +289,6 @@ def _(charting_library, mo, render_chart, token_prefix):
render_chart(
charting_library.value, _header
) if charting_library.value else None
- return
@app.cell(hide_code=True)
@@ -355,7 +342,6 @@ def _(mo):
mo.md(r"""
## CSVs, Parquet, Postgres, and more ...
""")
- return
@app.cell(hide_code=True)
@@ -376,7 +362,6 @@ def _(mo):
For this example, we will query an HTTP endpoint for a CSV.
""")
- return
@app.cell
@@ -391,7 +376,6 @@ def _(mo):
SELECT * from cars;
"""
)
- return
@app.cell(hide_code=True)
@@ -435,7 +419,6 @@ def _(filtered_cars, mo):
),
]
)
- return
@app.cell(hide_code=True)
diff --git a/marimo/_tutorials/ui.py b/marimo/_tutorials/ui.py
index 8453bb13e8..bea19d6ab0 100644
--- a/marimo/_tutorials/ui.py
+++ b/marimo/_tutorials/ui.py
@@ -8,7 +8,7 @@
import marimo
-__generated_with = "0.23.15"
+__generated_with = "0.25.2"
app = marimo.App()
@@ -21,7 +21,6 @@ def _(mo):
support for interactive user interface (UI) elements: interacting
with a UI element will automatically run cells that reference it.
""")
- return
@app.cell(hide_code=True)
@@ -29,7 +28,6 @@ def _(mo):
mo.md("""
## marimo.ui
""")
- return
@app.cell
@@ -52,7 +50,6 @@ def _(mo, slider):
mo.md(f"""
and here's its value: **{slider.value}**.
""")
- return
@app.cell(hide_code=True)
@@ -68,7 +65,6 @@ def _(mo):
drive the execution of your program, letting you build
interactive notebooks and tools for yourselves and others.
""")
- return
@app.cell(hide_code=True)
@@ -97,7 +93,6 @@ def _(mo, slider):
),
}
)
- return
@app.cell(hide_code=True)
@@ -105,7 +100,6 @@ def _(mo):
mo.md("""
### Simple elements
""")
- return
@app.cell(hide_code=True)
@@ -113,7 +107,6 @@ def _(mo):
mo.md("""
marimo has a [large library of simple UI elements](https://docs.marimo.io/api/inputs/index.html). Here are just a few examples:
""")
- return
@app.cell(hide_code=True)
@@ -124,7 +117,6 @@ def _(mo):
a more detailed reference, see our [API docs](https://docs.marimo.io/api/inputs/).
"""
).callout(kind="info", title="Examples and API reference")
- return
@app.cell
@@ -137,7 +129,6 @@ def _(mo):
@app.cell
def _(number):
number.value
- return
@app.cell
@@ -150,7 +141,6 @@ def _(mo):
@app.cell
def _(checkbox):
checkbox.value
- return
@app.cell
@@ -163,7 +153,6 @@ def _(mo):
@app.cell
def _(text):
text.value
- return
@app.cell
@@ -176,7 +165,6 @@ def _(mo):
@app.cell
def _(text_area):
text_area.value
- return
@app.cell
@@ -189,7 +177,6 @@ def _(mo):
@app.cell
def _(dropdown):
dropdown.value
- return
@app.cell
@@ -202,7 +189,6 @@ def _(mo):
@app.cell
def _(run_button):
"Run button was clicked!" if run_button.value else "Click the run button!"
- return
@app.cell
@@ -215,7 +201,6 @@ def _(mo):
@app.cell
def _(file_upload):
file_upload.value
- return
@app.cell
@@ -223,7 +208,6 @@ def _(basic_ui_elements, mo):
mo.md(f"""
To see more examples, use this dropdown: {basic_ui_elements}
""")
- return
@app.cell
@@ -236,13 +220,11 @@ def _(basic_ui_elements, construct_element, show_element):
@app.cell
def _(selected_element, value):
value(selected_element)
- return
@app.cell
def _(basic_ui_elements, documentation):
documentation(basic_ui_elements.value)
- return
@app.cell(hide_code=True)
@@ -250,7 +232,6 @@ def _(mo):
mo.md(r"""
`mo.ui.matrix` lets you edit 2D numeric data interactively.
""")
- return
@app.cell
@@ -270,7 +251,6 @@ def _(mo):
@app.cell
def _(matrix):
matrix.value
- return
@app.cell(hide_code=True)
@@ -285,7 +265,6 @@ def _(mo):
create a dynamic set of UI elements, or reduce the number of global
variables in your program.
""")
- return
@app.cell(hide_code=True)
@@ -295,7 +274,6 @@ def _(mo):
When you interact with an element in the array, all cells that reference the
array are reactively run. If you instead used a regular Python list, cells referring to the list would _not_ be run.
""")
- return
@app.cell
@@ -310,7 +288,6 @@ def _(mo):
@app.cell
def _(array):
array.value
- return
@app.cell(hide_code=True)
@@ -318,7 +295,6 @@ def _(mo):
mo.md(r"""
marimo also comes with `mo.ui.dictionary`, which is analogous to `mo.ui.array`
""")
- return
@app.cell
@@ -337,7 +313,6 @@ def _(mo):
@app.cell
def _(dictionary):
dictionary.value
- return
@app.cell(hide_code=True)
@@ -345,7 +320,6 @@ def _(composite_elements, mo):
mo.md(f"""
To see additional composite elements, use this dropdown: {composite_elements}
""")
- return
@app.cell
@@ -358,13 +332,11 @@ def _(composite_elements, construct_element, show_element):
@app.cell
def _(composite_element, value):
value(composite_element)
- return
@app.cell
def _(composite_elements, documentation):
documentation(composite_elements.value)
- return
@app.cell(hide_code=True)
@@ -377,7 +349,6 @@ def _(mo):
community. To learn more, [see our
docs](https://docs.marimo.io/guides/integrating_with_marimo/custom_ui_plugins.html).
""")
- return
@app.cell(hide_code=True)
@@ -388,7 +359,6 @@ def _(mo):
You can look at their code if you're curious how certain parts of this
tutorial were implemented.
""")
- return
@app.cell
diff --git a/pyproject.toml b/pyproject.toml
index dd0a0e2143..6295973eb1 100644
--- a/pyproject.toml
+++ b/pyproject.toml
@@ -378,7 +378,6 @@ ignore = [
"PT011", # `pytest.raises(ValueError)` is too broad, set the `match` parameter or use a more specific exception
"E501", # Line too long, we still trim
"D415", # First line should end with a period, question mark, or exclamation point
- "PLR1711", # Useless returns. We use this currently to delimit the end of a cell.
"ASYNC119", # Yield in context manager in async generator; required for streaming generators (LLM/SSE), no clean refactor
# Enabled by the Python 3.11 target. Both need deliberate migrations.
"ASYNC109", # Async function with a `timeout` parameter; callers should use `asyncio.timeout`
@@ -465,6 +464,7 @@ extend-select = [
"D211", # No blank lines allowed before class docstring
"D214", # Section is over-indented
"D215", # Section underline is over-indented
+ "PLR1711", # Useless return statements
"PLW1514", # Unspecified encoding in open()
"UP", # Upgrades
]
diff --git a/tests/_ast/codegen_data/test_app_with_annotation_typing.py b/tests/_ast/codegen_data/test_app_with_annotation_typing.py
index b909f7c152..8dc5336f22 100644
--- a/tests/_ast/codegen_data/test_app_with_annotation_typing.py
+++ b/tests/_ast/codegen_data/test_app_with_annotation_typing.py
@@ -23,7 +23,6 @@ def _():
@app.cell
def _(x: int, y: float, z: "int"):
_ = x + y + z
- return
if __name__ == "__main__":
diff --git a/tests/_ast/codegen_data/test_generate_filecontents.py b/tests/_ast/codegen_data/test_generate_filecontents.py
index 2b1f6d7fd4..2808c72e98 100644
--- a/tests/_ast/codegen_data/test_generate_filecontents.py
+++ b/tests/_ast/codegen_data/test_generate_filecontents.py
@@ -28,7 +28,6 @@ def three(x):
def four(np, x, y):
# comment
z = np.array(x + y)
- return
@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 55970d0843..63c42c6c89 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,6 @@ async def two(
async for data_point in client("test", "ws://localhost:8000"):
print(data_point)
data_point
- return
if __name__ == "__main__":
diff --git a/tests/_ast/codegen_data/test_generate_filecontents_shadowed_builtin.py b/tests/_ast/codegen_data/test_generate_filecontents_shadowed_builtin.py
index f0afa25b6a..4ddba63f3d 100644
--- a/tests/_ast/codegen_data/test_generate_filecontents_shadowed_builtin.py
+++ b/tests/_ast/codegen_data/test_generate_filecontents_shadowed_builtin.py
@@ -13,7 +13,6 @@ def one():
@app.cell
def two(type):
type
- 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 fbc0ccb959..f09c424a0d 100644
--- a/tests/_ast/codegen_data/test_generate_filecontents_single_cell.py
+++ b/tests/_ast/codegen_data/test_generate_filecontents_single_cell.py
@@ -8,8 +8,6 @@ app = marimo.App()
def one():
import numpy as np
- return
-
if __name__ == "__main__":
app.run()
diff --git a/tests/_ast/codegen_data/test_generate_filecontents_unshadowed_builtin.py b/tests/_ast/codegen_data/test_generate_filecontents_unshadowed_builtin.py
index 72986d475c..e1a66b6726 100644
--- a/tests/_ast/codegen_data/test_generate_filecontents_unshadowed_builtin.py
+++ b/tests/_ast/codegen_data/test_generate_filecontents_unshadowed_builtin.py
@@ -7,7 +7,6 @@ app = marimo.App()
@app.cell
def one():
type
- 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 575e5d4340..6e99a9f508 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
@@ -8,8 +8,6 @@ app = marimo.App()
def one():
import numpy as np
- return
-
app._unparsable_cell(
r"""
@@ -22,7 +20,6 @@ app._unparsable_cell(
@app.cell
def _():
'all good'
- 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 3fb2e103c0..6d3c99c164 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,6 @@ 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
if __name__ == "__main__":
diff --git a/tests/_ast/codegen_data/test_unparsable_cell_with_triple_quotes.py b/tests/_ast/codegen_data/test_unparsable_cell_with_triple_quotes.py
index 92668fcfa0..82378e014b 100644
--- a/tests/_ast/codegen_data/test_unparsable_cell_with_triple_quotes.py
+++ b/tests/_ast/codegen_data/test_unparsable_cell_with_triple_quotes.py
@@ -7,7 +7,6 @@ app = marimo.App()
@app.cell
def _():
x = 1
- return
app._unparsable_cell(
diff --git a/tests/_ast/test_cell.py b/tests/_ast/test_cell.py
index 65c8b0518d..4444a10344 100644
--- a/tests/_ast/test_cell.py
+++ b/tests/_ast/test_cell.py
@@ -413,7 +413,6 @@ class TestCellRun:
@app.cell
def basic(lots, of_, incorrect, args): # noqa: ARG001
1 # noqa: B018
- return
assert basic.run() == (1, {})
assert len(caplog.records) == 0
@@ -433,7 +432,6 @@ class TestCellRun:
else:
b = a
b # noqa: B018
- return
assert cyclic.run() == (1, {"a": 1, "b": 1})
assert cyclic() == 1
@@ -455,7 +453,6 @@ class TestReusableCell:
# non transitive
x = y - z
x # noqa: B018
- return
output, defs = uses_setup.run()
assert output == 0
@@ -484,7 +481,6 @@ class TestReusableCell:
def uses_setup(y):
z = y - x
z # noqa: B018
- return
output, defs = uses_setup.run()
assert output == 0
@@ -520,7 +516,6 @@ class TestReusableCell:
def uses_setup(y):
z = 0 * something_normally_scoped_for_a() + y - x
z # noqa: B018
- return
output, defs = uses_setup.run()
assert output == 0
@@ -621,7 +616,6 @@ def help_smoke() -> None:
@app.cell
async def f(x) -> None:
await x
- return
@app.cell
def g() -> None:
diff --git a/tests/_ast/test_codegen.py b/tests/_ast/test_codegen.py
index e44e939aa1..91d56075fa 100644
--- a/tests/_ast/test_codegen.py
+++ b/tests/_ast/test_codegen.py
@@ -876,9 +876,7 @@ class TestToFunctionDef:
code = "y + 1"
cell = compile_cell(code)
fndef = codegen.to_functiondef(cell, "foo")
- expected = "\n".join(
- ["@app.cell", "def foo(y):", " y + 1", " return"]
- )
+ expected = "\n".join(["@app.cell", "def foo(y):", " y + 1"])
assert fndef == expected
def test_tofunctiondef_empty_cells(self) -> None:
@@ -906,11 +904,54 @@ class TestToFunctionDef:
code = "print(y)"
cell = compile_cell(code)
fndef = codegen.to_functiondef(cell, "foo")
- expected = "\n".join(
- ["@app.cell", "def foo(y):", " print(y)", " return"]
- )
+ expected = "\n".join(["@app.cell", "def foo(y):", " print(y)"])
assert fndef == expected
+ def test_bare_return_stripped_unused_def(self) -> None:
+ # cell defines x, but x is not referenced by any other cell
+ # (used_refs=set()) -> defs=() -> bare return stripped
+ code = "x = 1"
+ cell = compile_cell(code)
+ fndef = codegen.to_functiondef(cell, "foo", used_refs=set())
+ assert "return" not in fndef
+ expected = "\n".join(["@app.cell", "def foo():", " x = 1"])
+ assert fndef == expected
+
+ def test_bare_return_kept_single_trailing_newline(self) -> None:
+ # cell.code ends with \n → blank line before return → keep return
+ code = "x = 1\n"
+ cell = compile_cell(code)
+ fndef = codegen.to_functiondef(cell, "foo", used_refs=set())
+ assert fndef.endswith(" return")
+
+ def test_bare_return_kept_multiple_trailing_newlines(self) -> None:
+ # cell.code ends with \n\n → multiple blank lines before return → keep return
+ code = "x = 1\n\n"
+ cell = compile_cell(code)
+ fndef = codegen.to_functiondef(cell, "foo", used_refs=set())
+ assert fndef.endswith(" return")
+
+ def test_bare_return_kept_only_comments(self) -> None:
+ # only comments, no AST statements → keep return (function must have a body)
+ code = "# just a comment"
+ cell = compile_cell(code)
+ fndef = codegen.to_functiondef(cell, "foo")
+ assert fndef.endswith(" return")
+
+ def test_bare_return_kept_empty_cell(self) -> None:
+ # empty cell → keep return (function must have a body)
+ code = ""
+ cell = compile_cell(code)
+ fndef = codegen.to_functiondef(cell, "foo")
+ assert fndef.endswith(" return")
+
+ def test_bare_return_kept_single_funcdef(self) -> None:
+ # single function def → keep return to prevent toplevel reclassification
+ code = "def helper():\n pass"
+ cell = compile_cell(code)
+ fndef = codegen.to_functiondef(cell, "foo", used_refs=set())
+ assert " return" in fndef
+
def test_tofunctiondef_refs_and_defs(self) -> None:
code = "\n".join(["y = x", "z = x", "z = w + y"])
cell = compile_cell(code)
@@ -1032,7 +1073,6 @@ class TestToFunctionDef:
"@app.cell",
"def cell2(cars_df, empty):",
" result = cars_df.filter(lambda x: x > 0); empty",
- " return",
]
)
in expected
@@ -1654,17 +1694,17 @@ def test_needs_trailing_blank_line(code: str, expected: bool) -> None:
@pytest.mark.parametrize(
("code", "expected_pattern", "unexpected_pattern"),
[
- # Import only - blank line before return
+ # Import only - return stripped (no blank line added)
(
"import datetime",
+ " import datetime",
" import datetime\n\n return",
- None,
),
- # Import then assignment - no blank line
+ # Import then assignment - return stripped (last stmt is assignment)
(
"import datetime\nx = 1",
+ " import datetime\n x = 1",
" import datetime\n x = 1\n return",
- None,
),
# Function def - blank line before return
(
@@ -1678,11 +1718,11 @@ def test_needs_trailing_blank_line(code: str, expected: bool) -> None:
" # comment\n return",
" # comment\n\n return",
),
- # Multiline import - blank line before return
+ # Multiline import - return stripped (no blank line added)
(
"from module import (\n a,\n b,\n)",
+ " from module import (\n a,\n b,\n )",
" )\n\n return",
- None,
),
],
ids=[
@@ -2220,8 +2260,7 @@ def _(x):
@app.cell
def _(foo):
- foo()
- return\
+ foo()\
"""
)
diff --git a/tests/_ast/test_pytest_scoped.py b/tests/_ast/test_pytest_scoped.py
index 929e2f321c..b69d49f89c 100644
--- a/tests/_ast/test_pytest_scoped.py
+++ b/tests/_ast/test_pytest_scoped.py
@@ -50,8 +50,6 @@ def collection_of_tests():
def test_uses_fixture(self, example):
assert example == "value"
- return
-
@app.cell
def _():
diff --git a/tests/_ast/test_toplevel.py b/tests/_ast/test_toplevel.py
index 4c3ee259ba..c7ea622ba4 100644
--- a/tests/_ast/test_toplevel.py
+++ b/tests/_ast/test_toplevel.py
@@ -632,7 +632,6 @@ class TestTopLevelHook:
@staticmethod
def method() -> None:
print(__class__)
- return
status = TopLevelStatus.from_cell(cell._cell, BUILTINS)
assert status.type == TopLevelType.TOPLEVEL
diff --git a/tests/_cli/snapshots/ipynb_to_marimo.txt b/tests/_cli/snapshots/ipynb_to_marimo.txt
index 61e6d27e3b..ce23d540f1 100644
--- a/tests/_cli/snapshots/ipynb_to_marimo.txt
+++ b/tests/_cli/snapshots/ipynb_to_marimo.txt
@@ -7,7 +7,6 @@ app = marimo.App()
@app.cell
def _():
print('Hello, World!')
- return
if __name__ == "__main__":
diff --git a/tests/_cli/snapshots/ipynb_to_marimo_with_output.txt b/tests/_cli/snapshots/ipynb_to_marimo_with_output.txt
index ed0a2f6e64..ce3be33aa7 100644
--- a/tests/_cli/snapshots/ipynb_to_marimo_with_output.txt
+++ b/tests/_cli/snapshots/ipynb_to_marimo_with_output.txt
@@ -7,7 +7,6 @@ app = marimo.App()
@app.cell
def _():
print('Hello, Output!')
- return
if __name__ == "__main__":
diff --git a/tests/_cli/snapshots/markdown_to_marimo.txt b/tests/_cli/snapshots/markdown_to_marimo.txt
index d5bb28aeb6..d1026fbd94 100644
--- a/tests/_cli/snapshots/markdown_to_marimo.txt
+++ b/tests/_cli/snapshots/markdown_to_marimo.txt
@@ -11,7 +11,6 @@ def _(mo):
print('Hello from Markdown!')
""")
- return
if __name__ == "__main__":
diff --git a/tests/_cli/snapshots/python_script_no_main_to_marimo.txt b/tests/_cli/snapshots/python_script_no_main_to_marimo.txt
index 10873c31b2..efb9a7c30b 100644
--- a/tests/_cli/snapshots/python_script_no_main_to_marimo.txt
+++ b/tests/_cli/snapshots/python_script_no_main_to_marimo.txt
@@ -12,7 +12,6 @@ def _():
y = 10
result = x + y
print(f"Result: {result}")
- return
if __name__ == "__main__":
diff --git a/tests/_cli/snapshots/python_script_to_marimo.txt b/tests/_cli/snapshots/python_script_to_marimo.txt
index 716c594786..60fbc715ce 100644
--- a/tests/_cli/snapshots/python_script_to_marimo.txt
+++ b/tests/_cli/snapshots/python_script_to_marimo.txt
@@ -18,7 +18,6 @@ def _():
sys.exit(0)
_main_()
- return
if __name__ == "__main__":
diff --git a/tests/_cli/snapshots/remote_ipynb_to_marimo.txt b/tests/_cli/snapshots/remote_ipynb_to_marimo.txt
index 9896e3055e..51cbf7ef04 100644
--- a/tests/_cli/snapshots/remote_ipynb_to_marimo.txt
+++ b/tests/_cli/snapshots/remote_ipynb_to_marimo.txt
@@ -7,7 +7,6 @@ app = marimo.App()
@app.cell
def _():
print('Hello from Remote Notebook!')
- return
if __name__ == "__main__":
diff --git a/tests/_cli/snapshots/remote_markdown_to_marimo.txt b/tests/_cli/snapshots/remote_markdown_to_marimo.txt
index bc669afe15..f3451a0b14 100644
--- a/tests/_cli/snapshots/remote_markdown_to_marimo.txt
+++ b/tests/_cli/snapshots/remote_markdown_to_marimo.txt
@@ -13,7 +13,6 @@ def _(mo):
print('Hello from Remote Markdown!')
```
""")
- return
if __name__ == "__main__":
diff --git a/tests/_convert/common/test_convert_format.py b/tests/_convert/common/test_convert_format.py
index c3ff1f0a32..fc0763ee15 100644
--- a/tests/_convert/common/test_convert_format.py
+++ b/tests/_convert/common/test_convert_format.py
@@ -62,13 +62,11 @@ app = marimo.App()
@app.cell
def _():
print('Hello')
- return
@app.cell
def _():
x = 5
- return
if __name__ == "__main__":
@@ -97,13 +95,11 @@ app = marimo.App()
@app.cell(hide_code=True)
def _():
print('Hello')
- return
@app.cell
def _():
x = 5
- return
if __name__ == "__main__":
diff --git a/tests/_convert/ipynb/fixtures/py/cell_config.py b/tests/_convert/ipynb/fixtures/py/cell_config.py
index e469661a61..9cdc17a6c5 100644
--- a/tests/_convert/ipynb/fixtures/py/cell_config.py
+++ b/tests/_convert/ipynb/fixtures/py/cell_config.py
@@ -22,7 +22,6 @@ def _(mo):
mo.md("""
# This cell is hidden
""")
- return
@app.cell(disabled=True)
@@ -34,13 +33,11 @@ def _(x):
@app.cell
def _(y):
print(y)
- return
@app.cell(expand_output=True)
def _(y):
z = y + 1
- return
if __name__ == "__main__":
diff --git a/tests/_convert/ipynb/fixtures/py/cell_names_and_defs.py b/tests/_convert/ipynb/fixtures/py/cell_names_and_defs.py
index fa47f3f657..ae2714d58d 100644
--- a/tests/_convert/ipynb/fixtures/py/cell_names_and_defs.py
+++ b/tests/_convert/ipynb/fixtures/py/cell_names_and_defs.py
@@ -21,7 +21,6 @@ def compute(os, sys):
@app.cell
def display(result):
print(result)
- return
@app.function
diff --git a/tests/_convert/ipynb/fixtures/py/complex_file_format.py b/tests/_convert/ipynb/fixtures/py/complex_file_format.py
index bee476da49..b3bc059548 100644
--- a/tests/_convert/ipynb/fixtures/py/complex_file_format.py
+++ b/tests/_convert/ipynb/fixtures/py/complex_file_format.py
@@ -28,7 +28,6 @@ def _():
- Feature 1
- Feature 2
""")
- return
@app.cell
@@ -45,7 +44,6 @@ def disabled_cell():
"""This cell is disabled."""
x = 42
should_not_run = True
- return
@app.cell
@@ -60,14 +58,12 @@ def analysis(df):
"""Named cell with analysis and markdown output."""
result = df["a"].sum()
mo.md(f"The sum is **{result}**")
- return
@app.cell
def _():
"""Unnamed cell."""
internal_var = 100
- return
@app.function
diff --git a/tests/_convert/ipynb/fixtures/py/complex_outputs.py b/tests/_convert/ipynb/fixtures/py/complex_outputs.py
index 081060b5f8..6e977ac684 100644
--- a/tests/_convert/ipynb/fixtures/py/complex_outputs.py
+++ b/tests/_convert/ipynb/fixtures/py/complex_outputs.py
@@ -18,7 +18,6 @@ def _(mo):
This notebook tests various output scenarios.
""")
- return
@app.cell
@@ -26,7 +25,6 @@ def _():
"""Cell with print statements."""
print("Standard output")
print("Multiple lines")
- return
@app.cell
@@ -42,7 +40,6 @@ def _(data):
"""Cell with calculations and implicit output."""
result = sum(data["x"]) + sum(data["y"])
result
- return
@app.cell
@@ -52,7 +49,6 @@ def _(mo):
print("Debug info")
value = 42
value
- return
@app.cell
@@ -64,7 +60,6 @@ def error_cell():
if hasattr(sys, "never_exists"):
raise ValueError("This should not happen")
success = True
- return
if __name__ == "__main__":
diff --git a/tests/_convert/ipynb/fixtures/py/markdown_variants.py b/tests/_convert/ipynb/fixtures/py/markdown_variants.py
index 75cb11dd41..aaf690494b 100644
--- a/tests/_convert/ipynb/fixtures/py/markdown_variants.py
+++ b/tests/_convert/ipynb/fixtures/py/markdown_variants.py
@@ -24,7 +24,6 @@ def _(mo):
Plain triple-quoted markdown.
""")
- return
@app.cell
@@ -34,7 +33,6 @@ def _(mo):
Raw triple-quoted markdown.
""")
- return
@app.cell
@@ -44,7 +42,6 @@ def _(mo):
F-string with no interpolation.
""")
- return
@app.cell
@@ -54,13 +51,11 @@ def _(mo):
FR-string with no interpolation.
""")
- return
@app.cell
def _(mo, x):
mo.md(f"The value is **{x}**")
- return
if __name__ == "__main__":
diff --git a/tests/_convert/ipynb/fixtures/py/notebook_metadata.py b/tests/_convert/ipynb/fixtures/py/notebook_metadata.py
index 7e9efab8d0..b84714ddb0 100644
--- a/tests/_convert/ipynb/fixtures/py/notebook_metadata.py
+++ b/tests/_convert/ipynb/fixtures/py/notebook_metadata.py
@@ -21,7 +21,6 @@ def _():
@app.cell
def _(x):
print(x)
- return
if __name__ == "__main__":
diff --git a/tests/_convert/ipynb/fixtures/py/setup_cell.py b/tests/_convert/ipynb/fixtures/py/setup_cell.py
index d24f0c394a..1364dbf79b 100644
--- a/tests/_convert/ipynb/fixtures/py/setup_cell.py
+++ b/tests/_convert/ipynb/fixtures/py/setup_cell.py
@@ -12,13 +12,11 @@ def _():
mo.md("""
# Hello from setup
""")
- return
@app.cell
def _():
x = 42
- return
if __name__ == "__main__":
diff --git a/tests/_convert/ipynb/fixtures/py/simple.py b/tests/_convert/ipynb/fixtures/py/simple.py
index 2bd8316c33..0a6467380b 100644
--- a/tests/_convert/ipynb/fixtures/py/simple.py
+++ b/tests/_convert/ipynb/fixtures/py/simple.py
@@ -16,7 +16,6 @@ def _(mo):
mo.md("""
# Hello, World!
""")
- return
@app.cell
@@ -30,7 +29,6 @@ def _():
@app.cell
def _(z):
print(z)
- return
if __name__ == "__main__":
diff --git a/tests/_convert/ipynb/snapshots/converted_cell_metadata.py.txt b/tests/_convert/ipynb/snapshots/converted_cell_metadata.py.txt
index 292aea871b..1c186a5391 100644
--- a/tests/_convert/ipynb/snapshots/converted_cell_metadata.py.txt
+++ b/tests/_convert/ipynb/snapshots/converted_cell_metadata.py.txt
@@ -7,53 +7,45 @@ app = marimo.App()
def _():
# Cell tags: tag1, tag2
print("Hello")
- return
@app.cell
def _():
print("World")
- return
@app.cell
def _():
# Cell tags: data-processing, important
print("Cell 1")
- return
@app.cell
def _():
print("Cell 2")
- return
@app.cell
def _():
# Cell tags: visualization
print("Cell 3")
- return
@app.cell
def _():
# Cell tags: tag1, tag2
print("Complex metadata")
- return
@app.cell(hide_code=True)
def _():
print("hidden cell")
- return
@app.cell(hide_code=True)
def _():
# Cell tags: remove-print
print("hidden cell, with other tags")
- return
if __name__ == "__main__":
diff --git a/tests/_convert/ipynb/snapshots/converted_comments_preservation.py.txt b/tests/_convert/ipynb/snapshots/converted_comments_preservation.py.txt
index 4b27cf5467..4ed9b8e76f 100644
--- a/tests/_convert/ipynb/snapshots/converted_comments_preservation.py.txt
+++ b/tests/_convert/ipynb/snapshots/converted_comments_preservation.py.txt
@@ -24,7 +24,6 @@ def _():
# This variable will be redefined later
y = 10 # First definition
print(y) # Should preserve this comment
- return
@app.cell
@@ -45,7 +44,6 @@ def _():
# Comment before magic
import os
os.listdir()
- return
@app.cell
@@ -55,7 +53,6 @@ def _(mo):
SELECT * FROM table -- Another SQL comment
WHERE id > 0 # Python-style comment in SQL
""")
- return
@app.cell
@@ -72,7 +69,6 @@ def _(np):
# Cell 7: Duplicate import with different comment
# This should be deduplicated but preserve one of the comments
arr = np.array([1, 2, 3]) # Create array
- return
@app.cell
@@ -81,7 +77,6 @@ def _(x, y_1):
# Calculate something complex
# Final comment in cell
z = x * 2 + y_1 # Multiply x by 2 # Add y to the result
- return
@app.cell
@@ -90,7 +85,6 @@ def _():
counter = 0 # Initialize counter
# This should preserve comments during aug assign transformation
counter = counter + 1 # Increment counter (this will be transformed)
- return
@app.cell
diff --git a/tests/_convert/ipynb/snapshots/converted_duplicate_definitions_and_aug_assign.py.txt b/tests/_convert/ipynb/snapshots/converted_duplicate_definitions_and_aug_assign.py.txt
index 01f4649150..b7596ecc6d 100644
--- a/tests/_convert/ipynb/snapshots/converted_duplicate_definitions_and_aug_assign.py.txt
+++ b/tests/_convert/ipynb/snapshots/converted_duplicate_definitions_and_aug_assign.py.txt
@@ -12,7 +12,6 @@ def _():
@app.cell
def _(x):
x
- return
@app.cell
@@ -24,7 +23,6 @@ def _(x):
@app.cell
def _(x_1):
x_1
- return
if __name__ == "__main__":
diff --git a/tests/_convert/ipynb/snapshots/converted_duplicate_definitions_read_before_write.py.txt b/tests/_convert/ipynb/snapshots/converted_duplicate_definitions_read_before_write.py.txt
index 4d7804c201..85b61178cf 100644
--- a/tests/_convert/ipynb/snapshots/converted_duplicate_definitions_read_before_write.py.txt
+++ b/tests/_convert/ipynb/snapshots/converted_duplicate_definitions_read_before_write.py.txt
@@ -12,7 +12,6 @@ def _():
@app.cell
def _(x):
x
- return
@app.cell
@@ -26,7 +25,6 @@ def _(x):
@app.cell
def _(x_1):
x_1
- return
if __name__ == "__main__":
diff --git a/tests/_convert/ipynb/snapshots/converted_duplicate_definitions_syntax_error.py.txt b/tests/_convert/ipynb/snapshots/converted_duplicate_definitions_syntax_error.py.txt
index af6594e572..89afb354f2 100644
--- a/tests/_convert/ipynb/snapshots/converted_duplicate_definitions_syntax_error.py.txt
+++ b/tests/_convert/ipynb/snapshots/converted_duplicate_definitions_syntax_error.py.txt
@@ -14,7 +14,6 @@ app._unparsable_cell(
@app.cell
def _(x):
x
- return
if __name__ == "__main__":
diff --git a/tests/_convert/ipynb/snapshots/converted_hides_markdown_cells.py.txt b/tests/_convert/ipynb/snapshots/converted_hides_markdown_cells.py.txt
index 277646b09f..ba301397c5 100644
--- a/tests/_convert/ipynb/snapshots/converted_hides_markdown_cells.py.txt
+++ b/tests/_convert/ipynb/snapshots/converted_hides_markdown_cells.py.txt
@@ -15,7 +15,6 @@ def _(mo):
mo.md(r"""
A markdown cell.
""")
- return
@app.cell(hide_code=True)
@@ -24,7 +23,6 @@ def _(mo):
mo.md(r"""
A markdown cell with tags: ['blah'].
""")
- return
@app.cell(hide_code=True)
@@ -33,7 +31,6 @@ def _(mo):
mo.md(r"""
A markdown cell with tags: ['blah', 'hide-cell'].
""")
- return
if __name__ == "__main__":
diff --git a/tests/_convert/ipynb/snapshots/converted_multiple_definitions.py.txt b/tests/_convert/ipynb/snapshots/converted_multiple_definitions.py.txt
index 54aca2a857..0c99875ed4 100644
--- a/tests/_convert/ipynb/snapshots/converted_multiple_definitions.py.txt
+++ b/tests/_convert/ipynb/snapshots/converted_multiple_definitions.py.txt
@@ -7,14 +7,12 @@ app = marimo.App()
def _():
_x = 1
print(_x) # print
- return
@app.cell
def _():
_x = 2
print(_x) # print
- return
if __name__ == "__main__":
diff --git a/tests/_convert/ipynb/snapshots/converted_multiple_definitions_multiline.py.txt b/tests/_convert/ipynb/snapshots/converted_multiple_definitions_multiline.py.txt
index e0218ec623..861248e128 100644
--- a/tests/_convert/ipynb/snapshots/converted_multiple_definitions_multiline.py.txt
+++ b/tests/_convert/ipynb/snapshots/converted_multiple_definitions_multiline.py.txt
@@ -17,7 +17,6 @@ def _(X_1, nearest_partition, plt):
for i_1 in range(X_1.shape[0]):
for j in nearest_partition[i_1, :_K + 1]:
plt.plot(*zip(X_1[j], X_1[i_1]), color='black')
- return
if __name__ == "__main__":
diff --git a/tests/_convert/ipynb/snapshots/converted_pip_commands.py.txt b/tests/_convert/ipynb/snapshots/converted_pip_commands.py.txt
index 9fc2e05d5f..94e7e9cf37 100644
--- a/tests/_convert/ipynb/snapshots/converted_pip_commands.py.txt
+++ b/tests/_convert/ipynb/snapshots/converted_pip_commands.py.txt
@@ -33,7 +33,6 @@ def _():
import numpy as np
# packages added via marimo's package management: seaborn !pip install seaborn
- return
@app.cell
@@ -43,7 +42,6 @@ def _(subprocess):
subprocess.call(['ls', '-la'])
#! echo 'Hello World'
subprocess.call(['echo', 'Hello World'])
- return
@app.cell
diff --git a/tests/_convert/ipynb/test_from_ir.py b/tests/_convert/ipynb/test_from_ir.py
index e2ba28dc48..24c3d96b53 100644
--- a/tests/_convert/ipynb/test_from_ir.py
+++ b/tests/_convert/ipynb/test_from_ir.py
@@ -92,7 +92,6 @@ def test_export_ipynb_marks_hidden_code_cells_for_nbconvert() -> None:
@app.cell()
def _(x):
print(x)
- return
ipynb_json = json.loads(
convert_from_ir_to_ipynb(InternalApp(app), sort_mode="top-down")
diff --git a/tests/_convert/markdown/snapshots/frontmatter-test.py.txt b/tests/_convert/markdown/snapshots/frontmatter-test.py.txt
index 3eb81eb427..c8314b6ec8 100644
--- a/tests/_convert/markdown/snapshots/frontmatter-test.py.txt
+++ b/tests/_convert/markdown/snapshots/frontmatter-test.py.txt
@@ -12,13 +12,11 @@ def _(mo):
mo.md(r"""
# Notebook
""")
- return
@app.cell
def _():
print("Hello, World!")
- return
if __name__ == "__main__":
diff --git a/tests/_convert/markdown/snapshots/no-frontmatter.py.txt b/tests/_convert/markdown/snapshots/no-frontmatter.py.txt
index 2ca5378e5e..2b1c08b81e 100644
--- a/tests/_convert/markdown/snapshots/no-frontmatter.py.txt
+++ b/tests/_convert/markdown/snapshots/no-frontmatter.py.txt
@@ -9,13 +9,11 @@ def _(mo):
mo.md(r"""
# My Notebook
""")
- return
@app.cell
def _():
print("Hello, World!")
- return
@app.cell(hide_code=True)
@@ -24,7 +22,6 @@ def _(mo):
**Appendix**
- This is the end of the notebook
""")
- return
if __name__ == "__main__":
diff --git a/tests/_convert/markdown/snapshots/sql-notebook.py.txt b/tests/_convert/markdown/snapshots/sql-notebook.py.txt
index de589726a5..936da875b6 100644
--- a/tests/_convert/markdown/snapshots/sql-notebook.py.txt
+++ b/tests/_convert/markdown/snapshots/sql-notebook.py.txt
@@ -9,7 +9,6 @@ def _(mo):
mo.md(r"""
# SQL notebook
""")
- return
@app.cell
@@ -33,7 +32,6 @@ def _(mem_engine, mo, my_table):
@app.cell
def _(export, mo):
_df = mo.sql("SELECT * FROM export;")
- return
if __name__ == "__main__":
diff --git a/tests/_convert/markdown/snapshots/unsafe-app.py.txt b/tests/_convert/markdown/snapshots/unsafe-app.py.txt
index d0e42e9d12..5f85844c0d 100644
--- a/tests/_convert/markdown/snapshots/unsafe-app.py.txt
+++ b/tests/_convert/markdown/snapshots/unsafe-app.py.txt
@@ -24,7 +24,6 @@ def _(mo):
print("Hello World")
```
""")
- return
@app.cell
@@ -35,7 +34,6 @@ def _(mo):
print("Hello World")
```
""")
- return
@app.cell
@@ -46,7 +44,6 @@ def _(mo):
print("1 + 1 = {1 + 1}")
```
""")
- return
@app.cell(hide_code=True)
@@ -58,7 +55,6 @@ def _(mo):
```python {.marimo}
````
""")
- return
@app.cell
@@ -66,7 +62,6 @@ def _():
"""
```
"""
- return
@app.cell
@@ -75,20 +70,17 @@ def _(mo):
Cross cell injection
```python
""")
- return
@app.cell
def _():
1 + 1
- return
@app.cell
def _():
# Actual print
print("Hello World")
- return
if __name__ == "__main__":
diff --git a/tests/_convert/markdown/snapshots/unsafe-doc.py.txt b/tests/_convert/markdown/snapshots/unsafe-doc.py.txt
index e727c024ed..04e59da1ee 100644
--- a/tests/_convert/markdown/snapshots/unsafe-doc.py.txt
+++ b/tests/_convert/markdown/snapshots/unsafe-doc.py.txt
@@ -14,13 +14,11 @@ def _(mo):
<!--
\
""")
- return
@app.cell
def _():
print("Hello, World!")
- return
@app.cell(hide_code=True)
@@ -30,7 +28,6 @@ def _(mo):
```marimo run convert document.md```
""")
- return
app._unparsable_cell(
@@ -50,13 +47,11 @@ def _(mo):
<!-- Disabled code block -->
""")
- return
@app.cell(disabled=True)
def _():
1 + 1
- return
@app.cell(hide_code=True)
@@ -64,13 +59,11 @@ def _(mo):
mo.md(r"""
<!-- Hidden code block -->
""")
- return
@app.cell(hide_code=True)
def _():
1 + 1
- return
@app.cell(hide_code=True)
@@ -78,7 +71,6 @@ def _(mo):
mo.md(r"""
<!-- Empty code block -->
""")
- return
@app.cell
@@ -91,7 +83,6 @@ def _(mo):
mo.md(r"""
<!-- Improperly nested code block -->
""")
- return
app._unparsable_cell(
@@ -121,7 +112,6 @@ def _(mo):
<!-- from the notebook, should remain unchanged -->
""")
- return
@app.cell
@@ -132,7 +122,6 @@ def _(mo):
# To ambiguous to convert
```
""")
- return
if __name__ == "__main__":
diff --git a/tests/_convert/markdown/test_markdown_from_ir.py b/tests/_convert/markdown/test_markdown_from_ir.py
index 51a116bd1e..68cb60cffc 100644
--- a/tests/_convert/markdown/test_markdown_from_ir.py
+++ b/tests/_convert/markdown/test_markdown_from_ir.py
@@ -120,7 +120,6 @@ def test_convert_from_ir_to_markdown_with_markdown_cell():
@app.cell()
def __(mo):
mo.md("# Hello World")
- return
internal_app = InternalApp(app)
notebook = internal_app.to_ir()
@@ -222,12 +221,10 @@ def test_convert_from_ir_to_markdown_consecutive_markdown_cells():
@app.cell()
def __(mo):
mo.md("# First markdown")
- return
@app.cell()
def __(mo):
mo.md("# Second markdown")
- return
internal_app = InternalApp(app)
notebook = internal_app.to_ir()
@@ -253,7 +250,6 @@ def test_convert_from_ir_to_markdown_with_column():
@app.cell(column=1)
def __(mo):
mo.md("# Markdown in column")
- return
internal_app = InternalApp(app)
notebook = internal_app.to_ir()
diff --git a/tests/_convert/snapshots/basic_marimo_example_roundtrip.py.txt b/tests/_convert/snapshots/basic_marimo_example_roundtrip.py.txt
index 18a76645eb..9db02faaaf 100644
--- a/tests/_convert/snapshots/basic_marimo_example_roundtrip.py.txt
+++ b/tests/_convert/snapshots/basic_marimo_example_roundtrip.py.txt
@@ -9,7 +9,6 @@ def _(mo):
mo.md(r"""
This is a simple marimo notebook
""")
- return
@app.cell
@@ -22,7 +21,6 @@ def _():
def _(x):
y = x+1
y
- return
@app.cell
diff --git a/tests/_convert/snapshots/minimal_script.py.txt b/tests/_convert/snapshots/minimal_script.py.txt
index 4f37b12132..1b1470c129 100644
--- a/tests/_convert/snapshots/minimal_script.py.txt
+++ b/tests/_convert/snapshots/minimal_script.py.txt
@@ -9,7 +9,6 @@ def _():
x = 5
y = 10
print(x + y)
- return
if __name__ == "__main__":
diff --git a/tests/_convert/snapshots/pypercent_format.py.txt b/tests/_convert/snapshots/pypercent_format.py.txt
index 09ba7831b1..66e090e0c5 100644
--- a/tests/_convert/snapshots/pypercent_format.py.txt
+++ b/tests/_convert/snapshots/pypercent_format.py.txt
@@ -26,7 +26,6 @@ def _(mo):
This is a markdown cell
with multiple lines
""")
- return
@app.cell(hide_code=True)
@@ -34,7 +33,6 @@ def _(mo):
mo.md(r"""
This is a doc string, but also markdown
""")
- return
@app.cell
@@ -50,7 +48,6 @@ def _(x):
# Cell with title
y = x * 2
print(y)
- return
if __name__ == "__main__":
diff --git a/tests/_convert/snapshots/pypercent_markdown_only.py.txt b/tests/_convert/snapshots/pypercent_markdown_only.py.txt
index ebe97f5c3a..a14951ee0e 100644
--- a/tests/_convert/snapshots/pypercent_markdown_only.py.txt
+++ b/tests/_convert/snapshots/pypercent_markdown_only.py.txt
@@ -14,7 +14,6 @@ def _():
@app.cell
def _():
"""Documentation in pypercent format."""
- return
@app.cell(hide_code=True)
@@ -23,7 +22,6 @@ def _(mo):
Introduction
This is a documentation file.
""")
- return
@app.cell(hide_code=True)
@@ -32,7 +30,6 @@ def _(mo):
Usage
Here's how to use this module.
""")
- return
if __name__ == "__main__":
diff --git a/tests/_convert/snapshots/pypercent_with_main.py.txt b/tests/_convert/snapshots/pypercent_with_main.py.txt
index 9ab1eb95ab..5b82633328 100644
--- a/tests/_convert/snapshots/pypercent_with_main.py.txt
+++ b/tests/_convert/snapshots/pypercent_with_main.py.txt
@@ -7,7 +7,6 @@ app = marimo.App()
@app.cell
def _():
"""Script with main block in pypercent."""
- return
@app.cell
@@ -24,7 +23,6 @@ def _(sys):
sys.exit(0)
_main_()
- return
if __name__ == "__main__":
diff --git a/tests/_convert/snapshots/simple_script.py.txt b/tests/_convert/snapshots/simple_script.py.txt
index c829a9d81c..6adee23b26 100644
--- a/tests/_convert/snapshots/simple_script.py.txt
+++ b/tests/_convert/snapshots/simple_script.py.txt
@@ -14,7 +14,6 @@ def _():
return math.pi * radius ** 2
print(calculate_area(5))
- return
if __name__ == "__main__":
diff --git a/tests/_export/test_exporter.py b/tests/_export/test_exporter.py
index 640e7f2412..3903c40260 100644
--- a/tests/_export/test_exporter.py
+++ b/tests/_export/test_exporter.py
@@ -325,14 +325,12 @@ async def test_run_notebook_with_stack_trace() -> None:
@app.cell()
def _():
print("running internal tests")
- return
@app.cell()
def _():
import sys
sys.stderr.write("internal error\n")
- return
@app.cell()
def _():
@@ -341,7 +339,6 @@ async def test_run_notebook_with_stack_trace() -> None:
raise ValueError(
"Failed to authenticate. The correct password is 's3cret'."
)
- return
file_manager = AppFileManager.from_app(InternalApp(app))
@@ -606,7 +603,6 @@ def test_export_as_html_omits_getpass_response(
import getpass
_password = getpass.getpass("Password: ")
- return
internal_app = InternalApp(app)
cell_id = next(iter(internal_app.cell_manager.cell_ids()))
diff --git a/tests/_runtime/test_pytest_runtime.py b/tests/_runtime/test_pytest_runtime.py
index 0d653d30d1..80186050f5 100644
--- a/tests/_runtime/test_pytest_runtime.py
+++ b/tests/_runtime/test_pytest_runtime.py
@@ -178,8 +178,6 @@ def test_live_collection_ignores_stale_disk(tmp_path) -> None:
def test_renamed_target():
assert True
- return
-
_, lcls = app.run()
lcls = dict(lcls)
defs = {"test_values", "test_added", "test_renamed_target"}
@@ -508,8 +506,6 @@ def test_rerun_keeps_lazily_imported_modules(tmp_path, monkeypatch) -> None:
fake_torch.seed()
assert local_helper.VALUE == 1
- return
-
notebook = tmp_path / "notebook.py"
notebook.write_text("import marimo\napp = marimo.App()\n")
@@ -588,8 +584,6 @@ def test_collection_skips_entries_beside_the_notebook_path(
def test_anchor():
assert True
- return
-
previous = os.environ.get("PYTEST_CURRENT_TEST", "")
os.environ.pop("PYTEST_CURRENT_TEST", None)
try:
@@ -642,8 +636,6 @@ def test_working_dir_conftest_applies_to_notebook_below_it(
def test_shared(shared_value):
assert shared_value == 7
- return
-
previous = os.environ.get("PYTEST_CURRENT_TEST", "")
os.environ.pop("PYTEST_CURRENT_TEST", None)
try:
@@ -690,8 +682,6 @@ def test_parent_conftest_applies_from_sibling_working_dir(
def test_shared(shared_value):
assert shared_value == 7
- return
-
previous = os.environ.get("PYTEST_CURRENT_TEST", "")
os.environ.pop("PYTEST_CURRENT_TEST", None)
try:
@@ -748,8 +738,6 @@ def test_project_config_applies_to_notebook_outside_working_dir(
assert (shared_value, project_helper.VALUE) == (7, 42)
- return
-
previous = os.environ.get("PYTEST_CURRENT_TEST", "")
os.environ.pop("PYTEST_CURRENT_TEST", None)
try:
diff --git a/tests/_save/test_cache.py b/tests/_save/test_cache.py
index ca254a6021..7405caeb3f 100644
--- a/tests/_save/test_cache.py
+++ b/tests/_save/test_cache.py
@@ -2201,7 +2201,6 @@ class TestCacheDecorator:
f()
assert f.hits == 0
assert f.base_block.execution_refs == {"ns"}
- return
@staticmethod
def test_execution_hash_same_block(app) -> None:
@@ -2243,7 +2242,6 @@ class TestCacheDecorator:
assert f.base_block.context_refs == {"ns"}, (
f.base_block.context_refs
)
- return
@staticmethod
def test_execution_hash_diff_block(app) -> None:
@@ -2277,7 +2275,6 @@ class TestCacheDecorator:
def __(f):
f()
assert f.base_block.execution_refs == {"ns", "z"}
- return
@staticmethod
def test_content_hash_define_after(app) -> None:
@@ -2315,7 +2312,6 @@ class TestCacheDecorator:
f.base_block.execution_refs
)
assert f.base_block.missing == {"ns"}, f.base_block.missing
- return
@staticmethod
def test_execution_hash_same_block_fails() -> None:
@@ -2354,7 +2350,6 @@ class TestCacheDecorator:
@app.cell
def _(f):
f()
- return
# Cannot hash the cell of the unhashable content, so it should fail
with pytest.raises(TypeError):
@@ -2386,7 +2381,6 @@ class TestCacheDecorator:
random.seed(1)
assert a == g("hello")
assert a != g("world")
- return
@staticmethod
def test_shadowed_kwargs(app) -> None:
@@ -2416,7 +2410,6 @@ class TestCacheDecorator:
assert g.hits == 1
assert g() == "hello"
assert g.hits == 2
- return
@staticmethod
def test_shadowed_state(app) -> None:
@@ -2441,7 +2434,6 @@ class TestCacheDecorator:
@app.cell
def __(v):
assert v == 3
- return
@staticmethod
def test_shadowed_state_redefined(app) -> None:
@@ -2467,7 +2459,6 @@ class TestCacheDecorator:
@app.cell
def __(v):
assert v == 3
- return
@staticmethod
def test_internal_shadowed(app) -> None:
@@ -2576,7 +2567,6 @@ class TestCacheDecorator:
assert state1() == a == A
assert state2() == b == B
assert state() == 3
- return
@staticmethod
def test_shadowed_ui(app) -> None:
@@ -2600,7 +2590,6 @@ class TestCacheDecorator:
@app.cell
def __(v):
assert v == 3
- return
@staticmethod
def test_cache_with_mutation_after_def(app) -> None:
@@ -2673,7 +2662,6 @@ class TestCacheDecorator:
with ThreadPoolExecutor(max_workers=2) as executor:
future = executor.submit(inner, extension)
assert future.result() == 5
- return
@pytest.mark.skipif(
not DependencyManager.pandas.has(),
diff --git a/tests/_save/test_external_decorators.py b/tests/_save/test_external_decorators.py
index 82eaee1043..199f95b86d 100644
--- a/tests/_save/test_external_decorators.py
+++ b/tests/_save/test_external_decorators.py
@@ -300,7 +300,6 @@ class TestAsExternalApp:
defs["x"].append(1)
_, defs = ex_app.run()
assert len(defs["x"]) == 1
- return
@staticmethod
async def test_as_external_app_in_kernel(
@@ -343,7 +342,6 @@ class TestAsExternalApp:
r1 = await ex_app.embed()
assert r1.defs["bar"] == 2
assert r1.defs["cache"](1) == 2
- return
@staticmethod
async def test_as_external_app_embedded_cloned(app) -> None:
@@ -357,7 +355,6 @@ class TestAsExternalApp:
r2 = await ex_app.clone().embed()
assert r2.defs["bar"] == 2
assert r2.defs["cache"](1) == 2
- return
@staticmethod
async def test_as_external_app_embedded_in_kernel(
diff --git a/tests/_save/test_hash.py b/tests/_save/test_hash.py
index 69e62035a0..98b6a5a804 100644
--- a/tests/_save/test_hash.py
+++ b/tests/_save/test_hash.py
@@ -534,8 +534,6 @@ class TestHash:
_ = sleep
return 42
- return
-
@app.cell
def _(mo, time):
@mo.cache
@@ -543,8 +541,6 @@ class TestHash:
_ = time.sleep
return 42
- return
-
@app.cell
def _(direct, module):
assert direct() == module(), "direct() != module()"
diff --git a/tests/_server/test_file_manager.py b/tests/_server/test_file_manager.py
index 6b674513dd..e36133da00 100644
--- a/tests/_server/test_file_manager.py
+++ b/tests/_server/test_file_manager.py
@@ -559,8 +559,6 @@ def test_to_code(app_file_manager: AppFileManager) -> None:
"def _():",
" import marimo as mo",
"",
- " return",
- "",
"",
'if __name__ == "__main__":',
" app.run()",
diff --git a/tests/_snippets/data/multi_markdown.py b/tests/_snippets/data/multi_markdown.py
index 2b57f35b8e..595c39529e 100644
--- a/tests/_snippets/data/multi_markdown.py
+++ b/tests/_snippets/data/multi_markdown.py
@@ -14,7 +14,6 @@ def __(mo):
This is the title cell with a description.
"""
)
- return
@app.cell
@@ -24,7 +23,6 @@ def __(mo):
This is a second markdown cell that should also be rendered.
"""
)
- return
@app.cell
diff --git a/tests/test_loggers.py b/tests/test_loggers.py
index 31f4928f14..1429542263 100644
--- a/tests/test_loggers.py
+++ b/tests/test_loggers.py
@@ -177,4 +177,3 @@ def test_file_handler_uses_windows_safe_on_windows(tmp_path: Path):
def clear_loggers():
# Clear the logger cache before each test
_LOGGERS.clear()
- return