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.
Python artificial-intelligencedagdata-sciencedata-visualizationdataflowdeveloper-toolsmachine-learningnotebookspipelinepythonreactivesqlweb-app
fix: (static parse) warn on bad cellconfig opposed to failing (#4524)
Dylan Madisettibe90509718de
diff --git a/marimo/_ast/cell.py b/marimo/_ast/cell.pyindex 5a5ac76ae7..cbde6af156 100644--- a/marimo/_ast/cell.py+++ b/marimo/_ast/cell.py@@ -38,8 +38,15 @@ class CellConfig:hide_code: bool = False@classmethod- def from_dict(cls, kwargs: dict[str, Any]) -> CellConfig:- return cls(**{k: v for k, v in kwargs.items() if k in CellConfigKeys})+ def from_dict(+ cls, kwargs: dict[str, Any], warn: bool = True+ ) -> CellConfig:+ config = cls(+ **{k: v for k, v in kwargs.items() if k in CellConfigKeys}+ )+ if warn and (invalid := set(kwargs.keys()) - CellConfigKeys):+ LOGGER.warning(f"Invalid config keys: {invalid}")+ return configdef asdict(self) -> dict[str, Any]:return dataclasses.asdict(self)diff --git a/marimo/_ast/cell_manager.py b/marimo/_ast/cell_manager.pyindex 33132a9b3a..c1cfbd3af2 100644--- a/marimo/_ast/cell_manager.py+++ b/marimo/_ast/cell_manager.py@@ -217,8 +217,8 @@ class CellManager:else:cell_id = self.create_cell_id()cell = ir_cell_factory(cell_def, cell_id=cell_id)- cell_config = CellConfig(- **cell_def.options,+ cell_config = CellConfig.from_dict(+ cell_def.options,)cell._cell.configure(cell_config)self._register_cell(cell, app=app)diff --git a/tests/_ast/codegen_data/test_get_bad_kwargs.py b/tests/_ast/codegen_data/test_get_bad_kwargs.pynew file mode 100644index 0000000000..dc34d081b6--- /dev/null+++ b/tests/_ast/codegen_data/test_get_bad_kwargs.py@@ -0,0 +1,9 @@+import marimo++app = marimo.App(+ kwarg_that_doesnt_exist="title",+)+[email protected](fake_kwarg=True)+def fake_kwarg():+ returndiff --git a/tests/_ast/test_load.py b/tests/_ast/test_load.pyindex 5075b77490..1a22df0927 100644--- a/tests/_ast/test_load.py+++ b/tests/_ast/test_load.py@@ -1,11 +1,13 @@# Copyright 2025 Marimo. All rights reserved.from __future__ import annotations+import loggingimport osimport textwrapimport pytest+from marimo import _loggersfrom marimo._ast import loadDIR_PATH = os.path.dirname(os.path.realpath(__file__))@@ -251,3 +253,20 @@ class TestGetCodes:assert app._config.layout_file == "layouts/layout.json"assert app._config.app_title == "title"assert app._config.auto_download == "html"++ @staticmethod+ def test_get_bad_kwargs(load_app, caplog) -> None:+ # Should be stderr since warn level+ with caplog.at_level(logging.WARNING):+ _loggers.marimo_logger().propagate = True+ app = load_app(get_filepath("test_get_bad_kwargs"))+ assert app is not None++ # Don't worry about the discrepancy since dynamic_load should not be in+ # prod.+ if load_app == load._static_load:+ assert len(caplog.records) == 2+ assert "fake_kwarg" in caplog.text+ else:+ assert len(caplog.records) == 1+ assert "kwarg_that_doesnt_exist" in caplog.text