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: cloning of forms in arrays/dicts (#1357)
Akshay Agrawal51bd86ac71d4
diff --git a/marimo/_plugins/ui/_impl/array.py b/marimo/_plugins/ui/_impl/array.pyindex 98f1e983f9..8077f79543 100644--- a/marimo/_plugins/ui/_impl/array.py+++ b/marimo/_plugins/ui/_impl/array.py@@ -125,7 +125,11 @@ class array(UIElement[Dict[str, JSONType], Sequence[object]]):return [e._value for e in self._elements]def _clone(self) -> array:- return array(elements=self.elements, label=self._label)+ return array(+ elements=self.elements,+ label=self._label,+ on_change=self._on_change,+ )def __len__(self) -> int:return len(self.elements)diff --git a/marimo/_plugins/ui/_impl/input.py b/marimo/_plugins/ui/_impl/input.pyindex 1a948329d9..25c751f329 100644--- a/marimo/_plugins/ui/_impl/input.py+++ b/marimo/_plugins/ui/_impl/input.py@@ -1531,6 +1531,3 @@ class form(UIElement[Optional[JSONTypeBound], Optional[T]]):return Noneself.element._update(value)return self.element.value-- def _clone(self) -> form[JSONTypeBound, T]:- return form(element=self.element)diff --git a/marimo/_smoke_tests/sidebar.py b/marimo/_smoke_tests/sidebar.pyindex 9a47249ac8..7f5ae21035 100644--- a/marimo/_smoke_tests/sidebar.py+++ b/marimo/_smoke_tests/sidebar.py@@ -1,3 +1,4 @@+# Copyright 2024 Marimo. All rights reserved.import marimo__generated_with = "0.5.1"diff --git a/tests/_plugins/ui/_impl/test_input.py b/tests/_plugins/ui/_impl/test_input.pyindex 9b13e59d30..ececb43e6e 100644--- a/tests/_plugins/ui/_impl/test_input.py+++ b/tests/_plugins/ui/_impl/test_input.py@@ -1,6 +1,8 @@# Copyright 2024 Marimo. All rights reserved.from __future__ import annotations+from typing import Any+import pytestfrom marimo._plugins import ui@@ -319,5 +321,14 @@ def test_on_change() -> None:assert state == [False, True]+def test_form_in_array_retains_on_change() -> None:+ def on_change(*args: Any) -> None:+ del args+ ...++ array = ui.array([ui.form(ui.checkbox(), on_change=on_change)])+ assert array[0]._on_change == on_change++# TODO(akshayka): test file# TODO(akshayka): test date