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: ensure `repr_mimebundle` handles empty include/exclude parameters gracefully (#7787)
Alonso Silva17bc1ee4aa98
diff --git a/marimo/_output/formatters/repr_formatters.py b/marimo/_output/formatters/repr_formatters.pyindex 0e49ace66c..69ac6589e1 100644--- a/marimo/_output/formatters/repr_formatters.py+++ b/marimo/_output/formatters/repr_formatters.py@@ -55,7 +55,10 @@ def maybe_get_repr_formatter(# Try to call _repr_mimebundle_ with include/exclude parametersif attr == "_repr_mimebundle_":try:- contents = method(include=[], exclude=[])+ contents = method(include=None, exclude=None)+ # Check if we got an empty result and retry without params+ if not contents:+ contents = method()except TypeError:# If that fails, call the method without parameterscontents = method()diff --git a/tests/_output/formatters/test_formatters.py b/tests/_output/formatters/test_formatters.pyindex ef378b15c7..7e2828406e 100644--- a/tests/_output/formatters/test_formatters.py+++ b/tests/_output/formatters/test_formatters.py@@ -341,6 +341,48 @@ def test_repr_mimebundle_with_exclude():assert content == {"application/json": {"message": "Hello, World!"}}+def test_repr_mimebundle_empty_include_fallback():+ """Test that _repr_mimebundle_ with empty include falls back."""++ class GraphvizLikeObject:+ def _repr_mimebundle_(self, include=None, exclude=None): # noqa: ARG002+ # Simulate graphviz (https://github.com/xflr6/graphviz) behavior: empty include means empty result+ if include is not None and len(include) == 0:+ return {}+ return {+ "image/svg+xml": "<svg>test content</svg>",+ "text/plain": "test content",+ }++ def __repr__(self):+ return "GraphvizLikeObject()"++ obj = GraphvizLikeObject()+ formatter = get_formatter(obj)+ assert formatter is not None+ mime, content = formatter(obj)+ assert mime == "application/vnd.marimo+mimebundle"+ assert content == {"image/svg+xml": "<svg>test content</svg>"}+++def test_repr_mimebundle_type_error_fallback():+ """Test that _repr_mimebundle_ TypeError falls back to no-param version."""++ class LegacyMimeBundle:+ def _repr_mimebundle_(self):+ return {+ "application/json": {"message": "Legacy format"},+ "text/plain": "Legacy format",+ }++ obj = LegacyMimeBundle()+ formatter = get_formatter(obj)+ assert formatter is not None+ mime, content = formatter(obj)+ assert mime == "application/vnd.marimo+mimebundle"+ assert content == {"application/json": {"message": "Legacy format"}}++def test_repr_returns_none():class ReprNone:def _repr_html_(self):