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.

improvement: single '_' function names to work with linting (#3143)

Myles Scolnicke5af6a0abd55
diff --git a/frontend/src/core/cells/__tests__/__snapshots__/cells.test.ts.snap b/frontend/src/core/cells/__tests__/__snapshots__/cells.test.ts.snap
index 5e8dc054cc..2e84b32c6e 100644
--- a/frontend/src/core/cells/__tests__/__snapshots__/cells.test.ts.snap
+++ b/frontend/src/core/cells/__tests__/__snapshots__/cells.test.ts.snap
@@ -17,7 +17,7 @@ exports[`cell reducer > can initialize stdin 1`] = `
"lastCodeRun": null,
"lastExecutionTime": null,
"lastRunStartTimestamp": null,
- "name": "__",
+ "name": "_",
"outline": null,
"output": null,
"runElapsedTimeMs": null,
@@ -46,7 +46,7 @@ exports[`cell reducer > can initialize stdin 2`] = `
"lastCodeRun": "",
"lastExecutionTime": null,
"lastRunStartTimestamp": null,
- "name": "__",
+ "name": "_",
"outline": null,
"output": null,
"runElapsedTimeMs": null,
@@ -75,7 +75,7 @@ exports[`cell reducer > can initialize stdin 3`] = `
"lastCodeRun": "",
"lastExecutionTime": null,
"lastRunStartTimestamp": null,
- "name": "__",
+ "name": "_",
"outline": null,
"output": null,
"runElapsedTimeMs": null,
@@ -104,7 +104,7 @@ exports[`cell reducer > can initialize stdin 4`] = `
"lastCodeRun": "",
"lastExecutionTime": null,
"lastRunStartTimestamp": 20,
- "name": "__",
+ "name": "_",
"outline": null,
"output": null,
"runElapsedTimeMs": null,
@@ -140,7 +140,7 @@ exports[`cell reducer > can initialize stdin 5`] = `
"lastCodeRun": "",
"lastExecutionTime": null,
"lastRunStartTimestamp": 20,
- "name": "__",
+ "name": "_",
"outline": null,
"output": null,
"runElapsedTimeMs": null,
@@ -176,7 +176,7 @@ exports[`cell reducer > can initialize stdin 6`] = `
"lastCodeRun": "",
"lastExecutionTime": null,
"lastRunStartTimestamp": 20,
- "name": "__",
+ "name": "_",
"outline": null,
"output": null,
"runElapsedTimeMs": null,
@@ -218,7 +218,7 @@ exports[`cell reducer > can initialize stdin 7`] = `
"lastCodeRun": "",
"lastExecutionTime": null,
"lastRunStartTimestamp": 20,
- "name": "__",
+ "name": "_",
"outline": null,
"output": null,
"runElapsedTimeMs": null,
@@ -261,7 +261,7 @@ exports[`cell reducer > can initialize stdin 8`] = `
"lastCodeRun": "",
"lastExecutionTime": null,
"lastRunStartTimestamp": 20,
- "name": "__",
+ "name": "_",
"outline": null,
"output": null,
"runElapsedTimeMs": null,
@@ -310,7 +310,7 @@ exports[`cell reducer > can initialize stdin 9`] = `
"lastCodeRun": "",
"lastExecutionTime": null,
"lastRunStartTimestamp": 20,
- "name": "__",
+ "name": "_",
"outline": null,
"output": null,
"runElapsedTimeMs": null,
@@ -339,7 +339,7 @@ exports[`cell reducer > can receive console when the cell is idle and will clear
"lastCodeRun": null,
"lastExecutionTime": null,
"lastRunStartTimestamp": null,
- "name": "__",
+ "name": "_",
"outline": null,
"output": null,
"runElapsedTimeMs": null,
@@ -375,7 +375,7 @@ exports[`cell reducer > can receive console when the cell is idle and will clear
"lastCodeRun": "",
"lastExecutionTime": null,
"lastRunStartTimestamp": null,
- "name": "__",
+ "name": "_",
"outline": null,
"output": null,
"runElapsedTimeMs": null,
@@ -411,7 +411,7 @@ exports[`cell reducer > can receive console when the cell is idle and will clear
"lastCodeRun": "",
"lastExecutionTime": null,
"lastRunStartTimestamp": null,
- "name": "__",
+ "name": "_",
"outline": null,
"output": null,
"runElapsedTimeMs": null,
@@ -440,7 +440,7 @@ exports[`cell reducer > can receive console when the cell is idle and will clear
"lastCodeRun": "",
"lastExecutionTime": null,
"lastRunStartTimestamp": 20,
- "name": "__",
+ "name": "_",
"outline": null,
"output": null,
"runElapsedTimeMs": null,
@@ -476,7 +476,7 @@ exports[`cell reducer > can receive console when the cell is idle and will clear
"lastCodeRun": "",
"lastExecutionTime": null,
"lastRunStartTimestamp": 20,
- "name": "__",
+ "name": "_",
"outline": null,
"output": null,
"runElapsedTimeMs": 2000,
@@ -505,7 +505,7 @@ exports[`cell reducer > can run a stale cell 1`] = `
"lastCodeRun": "mo.slider()",
"lastExecutionTime": null,
"lastRunStartTimestamp": null,
- "name": "__",
+ "name": "_",
"outline": null,
"output": null,
"runElapsedTimeMs": null,
@@ -534,7 +534,7 @@ exports[`cell reducer > can run a stale cell 2`] = `
"lastCodeRun": "mo.slider()",
"lastExecutionTime": null,
"lastRunStartTimestamp": null,
- "name": "__",
+ "name": "_",
"outline": null,
"output": null,
"runElapsedTimeMs": null,
@@ -563,7 +563,7 @@ exports[`cell reducer > can run a stopped cell 1`] = `
"lastCodeRun": "mo.md('This has an ancestor that was stopped')",
"lastExecutionTime": null,
"lastRunStartTimestamp": null,
- "name": "__",
+ "name": "_",
"outline": null,
"output": null,
"runElapsedTimeMs": null,
@@ -592,7 +592,7 @@ exports[`cell reducer > can run a stopped cell 2`] = `
"lastCodeRun": "mo.md('This has an ancestor that was stopped')",
"lastExecutionTime": null,
"lastRunStartTimestamp": 20,
- "name": "__",
+ "name": "_",
"outline": null,
"output": null,
"runElapsedTimeMs": null,
@@ -621,7 +621,7 @@ exports[`cell reducer > can run a stopped cell 3`] = `
"lastCodeRun": "mo.md('This has an ancestor that was stopped')",
"lastExecutionTime": null,
"lastRunStartTimestamp": 20,
- "name": "__",
+ "name": "_",
"outline": null,
"output": {
"channel": "marimo-error",
@@ -661,7 +661,7 @@ exports[`cell reducer > can run a stopped cell 4`] = `
"lastCodeRun": "mo.md('This has an ancestor that was stopped')",
"lastExecutionTime": null,
"lastRunStartTimestamp": 20,
- "name": "__",
+ "name": "_",
"outline": null,
"output": {
"channel": "marimo-error",
@@ -701,7 +701,7 @@ exports[`cell reducer > can run a stopped cell 5`] = `
"lastCodeRun": "mo.md('This has an ancestor that was stopped')",
"lastExecutionTime": null,
"lastRunStartTimestamp": 40,
- "name": "__",
+ "name": "_",
"outline": null,
"output": null,
"runElapsedTimeMs": null,
@@ -730,7 +730,7 @@ exports[`cell reducer > can run cell and receive cell messages 1`] = `
"lastCodeRun": null,
"lastExecutionTime": null,
"lastRunStartTimestamp": null,
- "name": "__",
+ "name": "_",
"outline": null,
"output": null,
"runElapsedTimeMs": null,
@@ -759,7 +759,7 @@ exports[`cell reducer > can run cell and receive cell messages 2`] = `
"lastCodeRun": null,
"lastExecutionTime": null,
"lastRunStartTimestamp": null,
- "name": "__",
+ "name": "_",
"outline": null,
"output": null,
"runElapsedTimeMs": null,
@@ -788,7 +788,7 @@ exports[`cell reducer > can run cell and receive cell messages 3`] = `
"lastCodeRun": "import marimo as mo",
"lastExecutionTime": null,
"lastRunStartTimestamp": null,
- "name": "__",
+ "name": "_",
"outline": null,
"output": null,
"runElapsedTimeMs": null,
@@ -817,7 +817,7 @@ exports[`cell reducer > can run cell and receive cell messages 4`] = `
"lastCodeRun": "import marimo as mo",
"lastExecutionTime": null,
"lastRunStartTimestamp": null,
- "name": "__",
+ "name": "_",
"outline": null,
"output": null,
"runElapsedTimeMs": null,
@@ -846,7 +846,7 @@ exports[`cell reducer > can run cell and receive cell messages 5`] = `
"lastCodeRun": "import marimo as mo",
"lastExecutionTime": null,
"lastRunStartTimestamp": 20,
- "name": "__",
+ "name": "_",
"outline": null,
"output": null,
"runElapsedTimeMs": null,
@@ -882,7 +882,7 @@ exports[`cell reducer > can run cell and receive cell messages 6`] = `
"lastCodeRun": "import marimo as mo",
"lastExecutionTime": null,
"lastRunStartTimestamp": 20,
- "name": "__",
+ "name": "_",
"outline": null,
"output": null,
"runElapsedTimeMs": null,
@@ -918,7 +918,7 @@ exports[`cell reducer > can run cell and receive cell messages 7`] = `
"lastCodeRun": "import marimo as mo",
"lastExecutionTime": null,
"lastRunStartTimestamp": 20,
- "name": "__",
+ "name": "_",
"outline": null,
"output": {
"channel": "output",
@@ -960,7 +960,7 @@ import numpy",
"lastCodeRun": "import marimo as mo",
"lastExecutionTime": null,
"lastRunStartTimestamp": 20,
- "name": "__",
+ "name": "_",
"outline": null,
"output": {
"channel": "output",
@@ -1001,7 +1001,7 @@ exports[`cell reducer > can run cell and receive cell messages 9`] = `
"lastCodeRun": "import marimo as mo",
"lastExecutionTime": null,
"lastRunStartTimestamp": 20,
- "name": "__",
+ "name": "_",
"outline": null,
"output": {
"channel": "output",
@@ -1043,7 +1043,7 @@ import numpy",
"lastCodeRun": "import marimo as mo",
"lastExecutionTime": null,
"lastRunStartTimestamp": 20,
- "name": "__",
+ "name": "_",
"outline": null,
"output": {
"channel": "output",
@@ -1086,7 +1086,7 @@ import numpy",
import numpy",
"lastExecutionTime": null,
"lastRunStartTimestamp": 50,
- "name": "__",
+ "name": "_",
"outline": null,
"output": {
"channel": "marimo-error",
@@ -1135,7 +1135,7 @@ import numpy",
import numpy",
"lastExecutionTime": null,
"lastRunStartTimestamp": 50,
- "name": "__",
+ "name": "_",
"outline": null,
"output": {
"channel": "marimo-error",
@@ -1173,7 +1173,7 @@ exports[`cell reducer > errors reset status to idle 1`] = `
"lastCodeRun": null,
"lastExecutionTime": null,
"lastRunStartTimestamp": null,
- "name": "__",
+ "name": "_",
"outline": null,
"output": null,
"runElapsedTimeMs": null,
@@ -1202,7 +1202,7 @@ exports[`cell reducer > errors reset status to idle 2`] = `
"lastCodeRun": null,
"lastExecutionTime": null,
"lastRunStartTimestamp": null,
- "name": "__",
+ "name": "_",
"outline": null,
"output": null,
"runElapsedTimeMs": null,
@@ -1231,7 +1231,7 @@ exports[`cell reducer > errors reset status to idle 3`] = `
"lastCodeRun": "import marimo as mo",
"lastExecutionTime": null,
"lastRunStartTimestamp": null,
- "name": "__",
+ "name": "_",
"outline": null,
"output": null,
"runElapsedTimeMs": null,
@@ -1260,7 +1260,7 @@ exports[`cell reducer > errors reset status to idle 4`] = `
"lastCodeRun": "import marimo as mo",
"lastExecutionTime": null,
"lastRunStartTimestamp": null,
- "name": "__",
+ "name": "_",
"outline": null,
"output": {
"channel": "marimo-error",
diff --git a/frontend/src/core/cells/__tests__/names.test.ts b/frontend/src/core/cells/__tests__/names.test.ts
index c41f2c1dc2..08b7c6ff3b 100644
--- a/frontend/src/core/cells/__tests__/names.test.ts
+++ b/frontend/src/core/cells/__tests__/names.test.ts
@@ -51,10 +51,12 @@ describe("getValidName", () => {
describe("displayCellName", () => {
it("should return the name if it is not the default cell name", () => {
expect(displayCellName("custom_name", 1)).toBe("custom_name");
+ expect(displayCellName("__abcd", 0)).toBe("__abcd");
});
it("should return the HTML cell ID if the name is the default cell name", () => {
expect(displayCellName(DEFAULT_CELL_NAME, 0)).toBe("cell-0");
expect(displayCellName(DEFAULT_CELL_NAME, 1)).toBe("cell-1");
+ expect(displayCellName("__", 0)).toBe("cell-0");
});
});
diff --git a/frontend/src/core/cells/names.ts b/frontend/src/core/cells/names.ts
index f7e079413b..14ba31c7bf 100644
--- a/frontend/src/core/cells/names.ts
+++ b/frontend/src/core/cells/names.ts
@@ -1,6 +1,6 @@
/* Copyright 2024 Marimo. All rights reserved. */
-export const DEFAULT_CELL_NAME = "__";
+export const DEFAULT_CELL_NAME = "_";
// Generated with `python scripts/print_banned_cell_names.py`
const DISALLOWED_NAMES = new Set([
@@ -90,8 +90,13 @@ export function getValidName(name: string, existingNames: string[]): string {
* Print the cell name if differs from DEFAULT_CELL_NAME
*/
export function displayCellName(name: string, cellIndex: number): string {
- if (name !== DEFAULT_CELL_NAME) {
- return name;
+ if (isInternalCellName(name)) {
+ return `cell-${cellIndex}`;
}
- return `cell-${cellIndex}`;
+ return name;
+}
+
+// Default cell names are "_" and "__" (for backwards compatibility)
+function isInternalCellName(name: string): boolean {
+ return name === DEFAULT_CELL_NAME || name === "__";
}
diff --git a/marimo/_ast/app.py b/marimo/_ast/app.py
index 235539c222..c6763037c2 100644
--- a/marimo/_ast/app.py
+++ b/marimo/_ast/app.py
@@ -27,6 +27,7 @@ from marimo._ast.errors import (
MultipleDefinitionError,
UnparsableError,
)
+from marimo._ast.names import DEFAULT_CELL_NAME
from marimo._config.config import WidthType
from marimo._messaging.mimetypes import KnownMimeType
from marimo._output.hypertext import Html
@@ -52,12 +53,6 @@ if TYPE_CHECKING:
LOGGER = _loggers.marimo_logger()
-DEFAULT_CELL_NAME = "__"
-
-
-def is_default_cell_name(name: str) -> bool:
- return name == DEFAULT_CELL_NAME
-
@dataclass
class _AppConfig:
diff --git a/marimo/_ast/codegen.py b/marimo/_ast/codegen.py
index a57db3da0d..196bdb823d 100644
--- a/marimo/_ast/codegen.py
+++ b/marimo/_ast/codegen.py
@@ -12,6 +12,7 @@ from marimo import __version__
from marimo._ast.app import App, _AppConfig
from marimo._ast.cell import CellConfig, CellImpl
from marimo._ast.compiler import compile_cell
+from marimo._ast.names import DEFAULT_CELL_NAME
from marimo._ast.visitor import Name
if TYPE_CHECKING:
@@ -174,6 +175,12 @@ def generate_filecontents(
unshadowed_builtins = set(builtins.__dict__.keys()) - defs
fndefs: list[str] = []
+
+ # Update old internal cell names to the new ones
+ for idx, name in enumerate(names):
+ if name == "__":
+ names[idx] = DEFAULT_CELL_NAME
+
for data, name in zip(cell_data, names):
if isinstance(data, CellImpl):
fndefs.append(to_functiondef(data, name, unshadowed_builtins))
diff --git a/marimo/_ast/names.py b/marimo/_ast/names.py
new file mode 100644
index 0000000000..712547f9c6
--- /dev/null
+++ b/marimo/_ast/names.py
@@ -0,0 +1,6 @@
+DEFAULT_CELL_NAME = "_"
+
+
+def is_internal_cell_name(name: str) -> bool:
+ # Include "__" (for backwards compatibility)
+ return name == DEFAULT_CELL_NAME or name == "__"
diff --git a/marimo/_cli/convert/markdown.py b/marimo/_cli/convert/markdown.py
index 29741e96df..d04e843a4e 100644
--- a/marimo/_cli/convert/markdown.py
+++ b/marimo/_cli/convert/markdown.py
@@ -26,6 +26,7 @@ from marimo._ast import codegen
from marimo._ast.app import App, InternalApp, _AppConfig
from marimo._ast.cell import Cell, CellConfig
from marimo._ast.compiler import compile_cell
+from marimo._ast.names import DEFAULT_CELL_NAME
from marimo._convert.utils import markdown_to_marimo
MARIMO_MD = "marimo-md"
@@ -110,7 +111,7 @@ def _tree_to_app_obj(root: Element) -> SafeWrap:
app = InternalApp(App(**app_config.asdict()))
for child in root:
- name = child.get("name", "__")
+ name = child.get("name", DEFAULT_CELL_NAME)
# Default to hiding markdown cells.
cell_config = get_cell_config_from_tag(
child, hide_code=child.tag == MARIMO_MD
@@ -134,7 +135,7 @@ def _tree_to_app_obj(root: Element) -> SafeWrap:
cell_id=cell_id,
code=source,
config=cell_config,
- name=name or "__",
+ name=name or DEFAULT_CELL_NAME,
cell=None,
)
@@ -148,7 +149,7 @@ def _tree_to_app(root: Element) -> str:
names: list[str] = []
cell_config: list[CellConfig] = []
for child in root:
- names.append(child.get("name", "__"))
+ names.append(child.get("name", DEFAULT_CELL_NAME))
cell_config.append(get_cell_config_from_tag(child))
sources.append(get_source_from_tag(child))
diff --git a/marimo/_convert/utils.py b/marimo/_convert/utils.py
index 4726fd770d..be3d2156c6 100644
--- a/marimo/_convert/utils.py
+++ b/marimo/_convert/utils.py
@@ -6,6 +6,7 @@ from typing import Optional
from marimo._ast import codegen
from marimo._ast.app import _AppConfig
from marimo._ast.cell import CellConfig
+from marimo._ast.names import DEFAULT_CELL_NAME
def markdown_to_marimo(source: str) -> str:
@@ -33,7 +34,7 @@ def generate_from_sources(
"""
return codegen.generate_filecontents(
sources,
- ["__" for _ in sources],
+ [DEFAULT_CELL_NAME for _ in sources],
[CellConfig() for _ in range(len(sources))],
config=config,
header_comments=header_comments,
diff --git a/marimo/_server/export/exporter.py b/marimo/_server/export/exporter.py
index 7c4f127483..2a83dc9838 100644
--- a/marimo/_server/export/exporter.py
+++ b/marimo/_server/export/exporter.py
@@ -9,8 +9,8 @@ from pathlib import Path
from typing import TYPE_CHECKING, Any, Literal, Optional, cast
from marimo import __version__, _loggers
-from marimo._ast.app import is_default_cell_name
from marimo._ast.cell import Cell, CellConfig, CellImpl
+from marimo._ast.names import DEFAULT_CELL_NAME, is_internal_cell_name
from marimo._config.config import (
DEFAULT_CONFIG,
DisplayConfig,
@@ -193,7 +193,7 @@ class Exporter:
cell.config.asdict_without_defaults()
)
name = file_manager.app.cell_manager.cell_name(cid)
- if not is_default_cell_name(name):
+ if not is_internal_cell_name(name):
marimo_metadata["name"] = name
if marimo_metadata:
notebook_cell["metadata"]["marimo"] = marimo_metadata
@@ -261,7 +261,7 @@ class Exporter:
# Config values are opt in, so only include if they are set.
attributes = cell_data.config.asdict()
attributes = {k: "true" for k, v in attributes.items() if v}
- if cell_data.name != "__":
+ if not is_internal_cell_name(cell_data.name):
attributes["name"] = cell_data.name
# No "cell" typically means not parseable. However newly added
# cells require compilation before cell is set.
@@ -401,7 +401,7 @@ def _create_notebook_cell(
import nbformat # ignore
markdown_string = get_markdown_from_cell(
- Cell(_name="__", _cell=cell), cell.code
+ Cell(_name=DEFAULT_CELL_NAME, _cell=cell), cell.code
)
if markdown_string is not None:
return nbformat.v4.new_markdown_cell(markdown_string, id=cell.cell_id)
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 3c6994a7e3..6a7972aade 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
@@ -19,7 +19,7 @@ app._unparsable_cell(
@app.cell
-def __():
+def _():
'all good'
return
@@ -31,7 +31,7 @@ app._unparsable_cell(
\t
""",
- name="__"
+ name="_"
)
diff --git a/tests/_ast/test_codegen.py b/tests/_ast/test_codegen.py
index 078a00f623..ac7e6e5d55 100644
--- a/tests/_ast/test_codegen.py
+++ b/tests/_ast/test_codegen.py
@@ -16,6 +16,7 @@ from marimo import __version__
from marimo._ast import codegen, compiler
from marimo._ast.app import App, InternalApp, _AppConfig
from marimo._ast.cell import CellConfig
+from marimo._ast.names import is_internal_cell_name
compile_cell = partial(compiler.compile_cell, cell_id="0")
@@ -263,6 +264,17 @@ class TestGeneration:
result = codegen.generate_app_constructor(config)
assert result == 'app = marimo.App(auto_download=["html"])'
+ @staticmethod
+ def test_generate_file_contents_overwrite_default_cell_names() -> None:
+ contents = wrap_generate_filecontents(
+ ["import numpy as np", "x = 0", "y = x + 1"],
+ ["is_named", "__", "__"],
+ )
+ # __9 and __10 are overwritten by the default names
+ assert "is_named" in contents
+ assert "def _" in contents
+ assert "def __" not in contents
+
class TestGetCodes:
@staticmethod
@@ -394,7 +406,7 @@ class TestGetCodes:
)
assert app is not None
cell_manager = app._cell_manager
- assert list(cell_manager.names()) == ["one", "two", "__", "__"]
+ assert list(cell_manager.names()) == ["one", "two", "_", "_"]
assert list(cell_manager.codes()) == [
"import numpy as np",
"_ error",
@@ -412,7 +424,7 @@ class TestGetCodes:
app = codegen.get_app(get_filepath("test_app_with_no_cells"))
assert app is not None
app._cell_manager.ensure_one_cell()
- assert list(app._cell_manager.names()) == ["__"]
+ assert list(app._cell_manager.names()) == ["_"]
assert list(app._cell_manager.codes()) == [""]
@@ -620,3 +632,11 @@ def test_sqls() -> None:
cell = compile_cell(code)
sqls = cell.sqls
assert sqls == ["SELECT * FROM foo", "ATTACH TABLE bar"]
+
+
+def test_is_internal_cell_name() -> None:
+ assert is_internal_cell_name("__")
+ assert is_internal_cell_name("_")
+ assert not is_internal_cell_name("___")
+ assert not is_internal_cell_name("__1213123123")
+ assert not is_internal_cell_name("foo")
diff --git a/tests/_cli/snapshots/converted_arithmetic.py.txt b/tests/_cli/snapshots/converted_arithmetic.py.txt
index 2b71d4dcb8..b65c220c12 100644
--- a/tests/_cli/snapshots/converted_arithmetic.py.txt
+++ b/tests/_cli/snapshots/converted_arithmetic.py.txt
@@ -4,14 +4,14 @@ app = marimo.App()
@app.cell
-def __():
+def _():
x = 0
x
return (x,)
@app.cell
-def __(x):
+def _(x):
x + 1
return
diff --git a/tests/_cli/snapshots/converted_blank.py.txt b/tests/_cli/snapshots/converted_blank.py.txt
index 5f24931fb6..a26325b0fb 100644
--- a/tests/_cli/snapshots/converted_blank.py.txt
+++ b/tests/_cli/snapshots/converted_blank.py.txt
@@ -4,7 +4,7 @@ app = marimo.App()
@app.cell
-def __():
+def _():
return
diff --git a/tests/_cli/snapshots/converted_juv.py.txt b/tests/_cli/snapshots/converted_juv.py.txt
index d033bf3f75..28e5a9f21e 100644
--- a/tests/_cli/snapshots/converted_juv.py.txt
+++ b/tests/_cli/snapshots/converted_juv.py.txt
@@ -11,7 +11,7 @@ app = marimo.App()
@app.cell
-def __():
+def _():
return
diff --git a/tests/_cli/snapshots/converted_markdown.py.txt b/tests/_cli/snapshots/converted_markdown.py.txt
index 23550e13d2..dceab66391 100644
--- a/tests/_cli/snapshots/converted_markdown.py.txt
+++ b/tests/_cli/snapshots/converted_markdown.py.txt
@@ -4,7 +4,7 @@ app = marimo.App()
@app.cell
-def __(mo):
+def _(mo):
mo.md(
r"""
# Hello, markdown
@@ -19,7 +19,7 @@ def __(mo):
@app.cell
-def __(mo):
+def _(mo):
mo.md(
r"""
Here is some math
@@ -31,7 +31,7 @@ def __(mo):
@app.cell
-def __():
+def _():
import marimo as mo
return (mo,)
diff --git a/tests/_cli/snapshots/converted_multiple_defs.py.txt b/tests/_cli/snapshots/converted_multiple_defs.py.txt
index 2118698478..1f1ea640ab 100644
--- a/tests/_cli/snapshots/converted_multiple_defs.py.txt
+++ b/tests/_cli/snapshots/converted_multiple_defs.py.txt
@@ -4,46 +4,46 @@ app = marimo.App()
@app.cell
-def __():
+def _():
_x = 0
_x
return
@app.cell
-def __():
+def _():
_x = 1
_x
return
@app.cell
-def __():
+def _():
y = 0
return (y,)
@app.cell
-def __():
+def _():
y_1 = 1
return (y_1,)
@app.cell
-def __(y_1):
+def _(y_1):
y_1
return
@app.cell
-def __():
+def _():
for _i in range(3):
print(_i)
return
@app.cell
-def __():
+def _():
for _i in range(4):
print(_i)
return
diff --git a/tests/_cli/snapshots/converted_unparsable.py.txt b/tests/_cli/snapshots/converted_unparsable.py.txt
index 2f4a8188d4..f730ecab41 100644
--- a/tests/_cli/snapshots/converted_unparsable.py.txt
+++ b/tests/_cli/snapshots/converted_unparsable.py.txt
@@ -9,12 +9,12 @@ app._unparsable_cell(
x = 0
""",
- name="__"
+ name="_"
)
@app.cell
-def __(x):
+def _(x):
x
return
diff --git a/tests/_cli/snapshots/frontmatter-test.py.txt b/tests/_cli/snapshots/frontmatter-test.py.txt
index ba78150164..bac7c77ccf 100644
--- a/tests/_cli/snapshots/frontmatter-test.py.txt
+++ b/tests/_cli/snapshots/frontmatter-test.py.txt
@@ -5,7 +5,7 @@ app = marimo.App(app_title="My Title")
@app.cell
-def __(mo):
+def _(mo):
mo.md(
r"""
# Notebook
@@ -15,7 +15,7 @@ def __(mo):
@app.cell
-def __():
+def _():
print("Hello, World!")
return
diff --git a/tests/_cli/snapshots/ipynb_to_marimo.txt b/tests/_cli/snapshots/ipynb_to_marimo.txt
index 062512c9e3..61e6d27e3b 100644
--- a/tests/_cli/snapshots/ipynb_to_marimo.txt
+++ b/tests/_cli/snapshots/ipynb_to_marimo.txt
@@ -5,7 +5,7 @@ app = marimo.App()
@app.cell
-def __():
+def _():
print('Hello, World!')
return
diff --git a/tests/_cli/snapshots/ipynb_to_marimo_with_output.txt b/tests/_cli/snapshots/ipynb_to_marimo_with_output.txt
index c33d731a61..ed0a2f6e64 100644
--- a/tests/_cli/snapshots/ipynb_to_marimo_with_output.txt
+++ b/tests/_cli/snapshots/ipynb_to_marimo_with_output.txt
@@ -5,7 +5,7 @@ app = marimo.App()
@app.cell
-def __():
+def _():
print('Hello, Output!')
return
diff --git a/tests/_cli/snapshots/markdown_to_marimo.txt b/tests/_cli/snapshots/markdown_to_marimo.txt
index fd3f037aaa..c876da843f 100644
--- a/tests/_cli/snapshots/markdown_to_marimo.txt
+++ b/tests/_cli/snapshots/markdown_to_marimo.txt
@@ -5,7 +5,7 @@ app = marimo.App()
@app.cell
-def __(mo):
+def _(mo):
mo.md(
r"""
# Test Markdown
diff --git a/tests/_cli/snapshots/unsafe-app.py.txt b/tests/_cli/snapshots/unsafe-app.py.txt
index 279b3102e8..69787965fe 100644
--- a/tests/_cli/snapshots/unsafe-app.py.txt
+++ b/tests/_cli/snapshots/unsafe-app.py.txt
@@ -5,13 +5,13 @@ app = marimo.App(app_title="Test Notebook")
@app.cell
-def __():
+def _():
import marimo as mo
return (mo,)
@app.cell
-def __(mo):
+def _(mo):
mo.md("""
# Code blocks in code blocks
Output code for Hello World!
@@ -27,7 +27,7 @@ def __(mo):
@app.cell
-def __(mo):
+def _(mo):
mo.md(f"""
with f-string too!
```{{python}}
@@ -38,7 +38,7 @@ def __(mo):
@app.cell
-def __(mo):
+def _(mo):
mo.md(f"""
Not markdown
```{{python}}
@@ -49,7 +49,7 @@ def __(mo):
@app.cell
-def __(mo):
+def _(mo):
mo.md(
r"""
Nested fence
@@ -63,7 +63,7 @@ def __(mo):
@app.cell
-def __():
+def _():
"""
```
"""
@@ -71,7 +71,7 @@ def __():
@app.cell
-def __(mo):
+def _(mo):
mo.md("""
Cross cell injection
```python
@@ -80,13 +80,13 @@ def __(mo):
@app.cell
-def __():
+def _():
1 + 1
return
@app.cell
-def __():
+def _():
# Actual print
print("Hello World")
return
diff --git a/tests/_cli/snapshots/unsafe-doc.py.txt b/tests/_cli/snapshots/unsafe-doc.py.txt
index 8fa6473866..69a880c9cb 100644
--- a/tests/_cli/snapshots/unsafe-doc.py.txt
+++ b/tests/_cli/snapshots/unsafe-doc.py.txt
@@ -5,7 +5,7 @@ app = marimo.App(app_title="Casually malicious md")
@app.cell
-def __(mo):
+def _(mo):
mo.md(
r"""
What happens if I just leave a \"\"\"
@@ -20,13 +20,13 @@ def __(mo):
@app.cell
-def __():
+def _():
print("Hello, World!")
return
@app.cell
-def __(mo):
+def _(mo):
mo.md(
r"""
-->
@@ -41,12 +41,12 @@ app._unparsable_cell(
r"""
it's an unparsable cell
""",
- name="__"
+ name="_"
)
@app.cell
-def __(mo):
+def _(mo):
mo.md(
r"""
<!-- Actually markdown -->
@@ -60,13 +60,13 @@ def __(mo):
@app.cell(disabled=True)
-def __():
+def _():
1 + 1
return
@app.cell
-def __(mo):
+def _(mo):
mo.md(
r"""
<!-- Hidden code block -->
@@ -76,13 +76,13 @@ def __(mo):
@app.cell(hide_code=True)
-def __():
+def _():
1 + 1
return
@app.cell
-def __(mo):
+def _(mo):
mo.md(
r"""
<!-- Empty code block -->
@@ -92,12 +92,12 @@ def __(mo):
@app.cell
-def __():
+def _():
return
@app.cell
-def __(mo):
+def _(mo):
mo.md(
r"""
<!-- Improperly nested code block -->
@@ -112,12 +112,12 @@ app._unparsable_cell(
```{python}
print(\"Hello, World!\")
""",
- name="__"
+ name="_"
)
@app.cell
-def __(mo):
+def _(mo):
mo.md(
r"""
\"\"\"
@@ -139,7 +139,7 @@ def __(mo):
@app.cell
-def __(mo):
+def _(mo):
mo.md("""
This is a markdown cell with an execution block in it
```{python}
@@ -150,7 +150,7 @@ def __(mo):
@app.cell
-def __():
+def _():
return
diff --git a/tests/_convert/test_convert_utils.py b/tests/_convert/test_convert_utils.py
index f2a6e1eafb..edd903b5af 100644
--- a/tests/_convert/test_convert_utils.py
+++ b/tests/_convert/test_convert_utils.py
@@ -37,13 +37,13 @@ app = marimo.App()
@app.cell
-def __():
+def _():
print('Hello')
return
@app.cell
-def __():
+def _():
x = 5
return (x,)
diff --git a/tests/_server/test_file_manager.py b/tests/_server/test_file_manager.py
index 75c95716a7..2d2e32257f 100644
--- a/tests/_server/test_file_manager.py
+++ b/tests/_server/test_file_manager.py
@@ -239,7 +239,7 @@ def test_to_code(app_file_manager: AppFileManager) -> None:
"",
"",
"@app.cell",
- "def __():",
+ "def _():",
" import marimo as mo",
" return (mo,)",
"",