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 deepcopy in from_anywidget.py (#5134)

jmsmdy7d0987275623
diff --git a/marimo/_plugins/ui/_impl/from_anywidget.py b/marimo/_plugins/ui/_impl/from_anywidget.py
index 703880ec57..065a7b3260 100644
--- a/marimo/_plugins/ui/_impl/from_anywidget.py
+++ b/marimo/_plugins/ui/_impl/from_anywidget.py
@@ -3,6 +3,7 @@ from __future__ import annotations
import hashlib
import weakref
+from copy import deepcopy
from dataclasses import dataclass
from typing import TYPE_CHECKING, Any, Optional
@@ -190,6 +191,11 @@ class anywidget(UIElement[T, T]):
self._prev_state = value
return value
+ def __deepcopy__(self, memo):
+ # Overriding UIElement deepcopy implementation
+ widget_deep_copy = deepcopy(self.widget, memo)
+ return from_anywidget(widget_deep_copy) # reuse caching
+
# After the widget has been initialized
# forward all setattr to the widget
def __setattr__(self, name: str, value: Any) -> None: