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: check for state getter using is operator (#97)

Akshay Agrawal816892181844
diff --git a/marimo/_runtime/cell_runner.py b/marimo/_runtime/cell_runner.py
index f768d02e78..4437ebe4fd 100644
--- a/marimo/_runtime/cell_runner.py
+++ b/marimo/_runtime/cell_runner.py
@@ -245,8 +245,9 @@ class Runner:
continue
# State object in refs (5)
for ref in cell.refs:
- # run this cell if any of its refs match the state
- if ref in self.glbls and self.glbls[ref] == state:
+ # run this cell if any of its refs match the state object
+ # by object ID (via is operator)
+ if ref in self.glbls and self.glbls[ref] is state:
cids_to_run.add(cid)
return cids_to_run
diff --git a/marimo/_runtime/test_state.py b/marimo/_runtime/test_state.py
index 613fdf25e2..8e20710d21 100644
--- a/marimo/_runtime/test_state.py
+++ b/marimo/_runtime/test_state.py
@@ -125,3 +125,33 @@ def test_cancelled_not_run(k: Kernel, exec_req: ExecReqProvider) -> None:
)
assert "y" not in k.globals
+
+
+def test_set_state_with_overriden_eq(
+ k: Kernel, exec_req: ExecReqProvider
+) -> None:
+ create_class = """
+ class A:
+ def __eq__(self, other):
+ # shouldn't be triggered by marimo
+ import sys
+ sys.exit()
+ a = A()
+ """
+ k.run(
+ [
+ exec_req.get("import marimo as mo"),
+ exec_req.get(create_class),
+ exec_req.get("state, set_state = mo.state(None)"),
+ exec_req.get("x = state()"),
+ exec_req.get(
+ """
+ x
+ if x is None:
+ set_state(a)
+ """
+ ),
+ ]
+ )
+
+ assert type(k.globals["x"]).__name__ == "A"