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: parsing in python-314 (#7227)

Dylan Madisettia255d5a33d90
diff --git a/marimo/_ast/parse.py b/marimo/_ast/parse.py
index 9cda622364..3f3a54dcd3 100644
--- a/marimo/_ast/parse.py
+++ b/marimo/_ast/parse.py
@@ -3,6 +3,7 @@ from __future__ import annotations
import ast
import io
+import sys
import token as token_types
import warnings
from pathlib import Path
@@ -187,7 +188,7 @@ class Extractor:
if node.lineno - node.body[0].lineno == 0:
# Quirk where the ellipse token seems to have a line index at
# the end of the dots ...<
- if isinstance(getattr(node.body[0], "value", None), ast.Ellipsis):
+ if _is_ellipsis(getattr(node.body[0], "value", None)):
col_offset += node.body[0].col_offset - 3
else:
col_offset += node.body[0].col_offset - 1
@@ -909,6 +910,14 @@ def is_body_cell(node: Node) -> bool:
) or is_unparsable_cell(node)
+def _is_ellipsis(node: Optional[Node]) -> bool:
+ if node is None:
+ return False
+ if sys.version_info < (3, 14):
+ return isinstance(node, ast.Ellipsis)
+ return isinstance(node, ast.Constant) and node.value == ...
+
+
def _is_setup_call(node: Node) -> bool:
if isinstance(node, ast.Attribute):
return (
diff --git a/tests/_ast/codegen_data/test_get_codes_single_line_fn.py b/tests/_ast/codegen_data/test_get_codes_single_line_fn.py
index 10ab2db776..e814937025 100644
--- a/tests/_ast/codegen_data/test_get_codes_single_line_fn.py
+++ b/tests/_ast/codegen_data/test_get_codes_single_line_fn.py
@@ -7,6 +7,9 @@ app = marimo.App()
@app.cell
def one(a: int, b: int) -> None: c = a + b; print(c); return (c,)
+def two(a: int, b: int) -> None: ...
+
if __name__ == "__main__":
app.run()
diff --git a/tests/_ast/test_load.py b/tests/_ast/test_load.py
index 8cfab78b2a..04e419760f 100644
--- a/tests/_ast/test_load.py
+++ b/tests/_ast/test_load.py
@@ -170,8 +170,8 @@ class TestGetCodes:
app = load_app(get_filepath("test_get_codes_single_line_fn"))
assert app is not None
cell_manager = app._cell_manager
- assert list(cell_manager.names()) == ["one"]
- assert list(cell_manager.codes()) == ["c = a + b; print(c); "]
+ assert list(cell_manager.names()) == ["one", "two"]
+ assert list(cell_manager.codes()) == ["c = a + b; print(c); ", "..."]
@staticmethod
def test_get_codes_multiline_string(load_app) -> None: