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: Allow parsing lists in app config kwargs (#6427)

Dylan Madisettia5928d1e3ad8
diff --git a/marimo/_ast/app_config.py b/marimo/_ast/app_config.py
index 3e4050c659..15bd1018be 100644
--- a/marimo/_ast/app_config.py
+++ b/marimo/_ast/app_config.py
@@ -18,6 +18,9 @@ class _AppConfig:
a single marimo program.
"""
+ # NB. The addition of non-constant types here maybe have to be reflected in
+ # marimo._ast.parse since these values are read statically.
+
width: WidthType = "compact"
app_title: Optional[str] = None
diff --git a/marimo/_ast/parse.py b/marimo/_ast/parse.py
index 76ea5ea4a7..3bd8dda895 100644
--- a/marimo/_ast/parse.py
+++ b/marimo/_ast/parse.py
@@ -635,9 +635,23 @@ def _eval_kwargs(
kwargs = {}
violations = []
for kw in keywords:
- # Only accept Constants
+ # Only accept Constants, or lists of constants
if kw.arg and isinstance(kw.value, ast.Constant):
kwargs[kw.arg] = kw.value.value
+ elif kw.arg and isinstance(kw.value, ast.List):
+ list_values = []
+ for elt in kw.value.elts:
+ if isinstance(elt, ast.Constant):
+ list_values.append(elt.value)
+ else:
+ violations.append(
+ Violation(
+ UNEXPECTED_KEYWORD_VALUE_VIOLATION,
+ lineno=elt.lineno,
+ col_offset=elt.col_offset,
+ )
+ )
+ kwargs[kw.arg] = list_values
else:
violations.append(
Violation(
diff --git a/tests/_ast/test_parse.py b/tests/_ast/test_parse.py
index 4206081b54..4fbff36b18 100644
--- a/tests/_ast/test_parse.py
+++ b/tests/_ast/test_parse.py
@@ -1,9 +1,10 @@
# Copyright 2025 Marimo. All rights reserved.
from __future__ import annotations
+import ast
from pathlib import Path
-from marimo._ast.parse import Parser, parse_notebook
+from marimo._ast.parse import Parser, _eval_kwargs, parse_notebook
DIR_PATH = Path(__file__).parent
@@ -131,6 +132,59 @@ class TestParser:
# TODO: Propagate decorators violations.
assert len(notebook.violations) == 0
+ @staticmethod
+ def test_eval_kwargs_with_list_constants() -> None:
+ """Test that _eval_kwargs correctly handles list constants in kwargs."""
+ # Test case: marimo.App(width="medium", auto_download=["html"])
+
+ # Create AST nodes for the keyword arguments
+ width_kw = ast.keyword(arg="width", value=ast.Constant(value="medium"))
+
+ auto_download_kw = ast.keyword(
+ arg="auto_download",
+ value=ast.List(elts=[ast.Constant(value="html")], ctx=ast.Load()),
+ )
+
+ keywords = [width_kw, auto_download_kw]
+
+ # Test the function
+ kwargs, violations = _eval_kwargs(keywords)
+
+ # Verify results
+ assert len(violations) == 0
+ assert kwargs["width"] == "medium"
+ assert kwargs["auto_download"] == ["html"]
+
+ @staticmethod
+ def test_eval_kwargs_with_invalid_list_elements() -> None:
+ """Test that _eval_kwargs handles invalid elements in list kwargs."""
+ # Create a list with both valid and invalid elements
+ invalid_name_node = ast.Name(id="invalid_var", ctx=ast.Load())
+ invalid_name_node.lineno = 1
+ invalid_name_node.col_offset = 0
+
+ invalid_list_kw = ast.keyword(
+ arg="test_arg",
+ value=ast.List(
+ elts=[
+ ast.Constant(value="valid"),
+ invalid_name_node, # Invalid: not a constant
+ ],
+ ctx=ast.Load(),
+ ),
+ )
+
+ keywords = [invalid_list_kw]
+
+ # Test the function
+ kwargs, violations = _eval_kwargs(keywords)
+
+ # Should have one violation for the invalid element
+ assert len(violations) == 1
+ assert kwargs["test_arg"] == [
+ "valid"
+ ] # Should still include valid elements
+
@staticmethod
def test_parse_non_marimo() -> None:
import pytest