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
tidy: remove dynamic fallback, move strictly to testing (#8125)
Dylan Madisetti7608b3c8f0c4
diff --git a/marimo/_ast/load.py b/marimo/_ast/load.pyindex 3518325144..6eaafcfe28 100644--- a/marimo/_ast/load.py+++ b/marimo/_ast/load.py@@ -1,8 +1,6 @@# Copyright 2026 Marimo. All rights reserved.from __future__ import annotations-import importlib.util-import sysfrom dataclasses import dataclassfrom pathlib import Pathfrom typing import Literal, Optional, Union@@ -57,33 +55,6 @@ def _maybe_contents(filename: Optional[Union[str, Path]]) -> Optional[str]:return Path(filename).read_text(encoding="utf-8").strip()-# Used in tests and current fallback-def _dynamic_load(filename: str | Path) -> Optional[App]:- """Create and execute a module with the provided filename."""- contents = _maybe_contents(filename)- if not contents:- return None-- spec = importlib.util.spec_from_file_location("marimo_app", filename)- if spec is None:- raise RuntimeError("Failed to load module spec")- marimo_app = importlib.util.module_from_spec(spec)- if spec.loader is None:- raise RuntimeError("Failed to load module spec's loader")- try:- sys.modules["marimo_app"] = marimo_app- spec.loader.exec_module(marimo_app) # This may throw a SyntaxError- finally:- sys.modules.pop("marimo_app", None)- if not hasattr(marimo_app, "app"):- return None- if not isinstance(marimo_app.app, App):- raise MarimoFileError("`app` attribute must be of type `marimo.App`.")-- app = marimo_app.app- return app--def find_cell(filename: str, lineno: int) -> CellDef | None:"""Find the cell at the given line number in the notebook.@@ -161,8 +132,8 @@ def get_notebook_status(filename: str) -> LoadResult:FAILED_LOAD_NOTEBOOK_MESSAGE = (- "Static loading of notebook failed; falling back to dynamic loading. "- "If you can, please report this issue to the marimo team and include your notebook if possible — "+ "Static loading of notebook failed. "+ "Please report this issue to the marimo team and include your notebook if possible — ""https://github.com/marimo-team/marimo/issues/new?template=bug_report.yaml")@@ -209,9 +180,6 @@ def load_app(filename: Optional[str | Path]) -> Optional[App]:app = load_notebook_ir(notebook_ir)app._cell_manager.ensure_one_cell()return app- except MarimoFileError:- # Security advantages of static load are lost here, but reasonable- # fallback for now.- _app = _dynamic_load(filename)- LOGGER.warning(FAILED_LOAD_NOTEBOOK_MESSAGE)- return _app+ except MarimoFileError as e:+ LOGGER.error(FAILED_LOAD_NOTEBOOK_MESSAGE)+ raise MarimoFileError(FAILED_LOAD_NOTEBOOK_MESSAGE) from ediff --git a/tests/_ast/conftest.py b/tests/_ast/conftest.pynew file mode 100644index 0000000000..82907236f0--- /dev/null+++ b/tests/_ast/conftest.py@@ -0,0 +1,54 @@+# Copyright 2026 Marimo. All rights reserved.+"""Pytest fixtures for _ast tests."""++from __future__ import annotations++import importlib.util+import sys+from pathlib import Path+from typing import Optional++import pytest++from marimo._ast.app import App+from marimo._ast.parse import MarimoFileError+++def _dynamic_load(filename: str | Path) -> Optional[App]:+ """Create and execute a module with the provided filename.++ Test utility for backward compatibility testing. Not for production use.+ """+ if filename is None:+ return None++ path = Path(filename)+ contents = (+ path.read_text(encoding="utf-8").strip() if path.exists() else None+ )+ if not contents:+ return None++ spec = importlib.util.spec_from_file_location("marimo_app", filename)+ if spec is None:+ raise RuntimeError("Failed to load module spec")+ marimo_app = importlib.util.module_from_spec(spec)+ if spec.loader is None:+ raise RuntimeError("Failed to load module spec's loader")+ try:+ sys.modules["marimo_app"] = marimo_app+ spec.loader.exec_module(marimo_app)+ finally:+ sys.modules.pop("marimo_app", None)+ if not hasattr(marimo_app, "app"):+ return None+ if not isinstance(marimo_app.app, App):+ raise MarimoFileError("`app` attribute must be of type `marimo.App`.")++ return marimo_app.app+++def dynamic_load():+ """Direct dynamic load for backward compatibility testing."""+ return _dynamic_loaddiff --git a/tests/_ast/test_load.py b/tests/_ast/test_load.pyindex 06bad56c5c..b19ba81f5f 100644--- a/tests/_ast/test_load.py+++ b/tests/_ast/test_load.py@@ -65,12 +65,6 @@ def unified_load():return load.load_app-def dynamic_load():- """Direct dynamic load for backward compatibility testing."""- return load._dynamic_load--@pytest.fixture(params=["unified_load", "dynamic_load"])def load_app(request):"""Parametrized fixture to test both load paths."""@@ -327,8 +321,7 @@ class TestGetCodes: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.+ # dynamic_load is a test utility, not used in productionif load_app == load.load_app:assert len(caplog.records) == 2assert "fake_kwarg" in caplog.text