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
chore: _anywidget -> anywidget (#912)
Akshay Agrawalb8ce1be4559d
diff --git a/docs/api/inputs/anywidget.md b/docs/api/inputs/anywidget.mdindex ede818fbe7..0144179e77 100644--- a/docs/api/inputs/anywidget.md+++ b/docs/api/inputs/anywidget.md@@ -65,8 +65,8 @@ widget.value---```{eval-rst}-.. autoclass:: marimo._plugins.ui._impl.from_anywidget._anywidget+.. autoclass:: marimo.ui.anywidget:members:- .. autoclasstoc:: marimo._plugins.ui._impl.from_anywidget._anywidget+ .. autoclasstoc:: marimo._plugins.ui._impl.from_anywidget.anywidget```diff --git a/marimo/_plugins/ui/__init__.py b/marimo/_plugins/ui/__init__.pyindex 20ea5d6a27..debe548079 100644--- a/marimo/_plugins/ui/__init__.py+++ b/marimo/_plugins/ui/__init__.py@@ -40,7 +40,7 @@ from marimo._plugins.ui._impl.batch import batchfrom marimo._plugins.ui._impl.data_explorer import data_explorerfrom marimo._plugins.ui._impl.dataframes.dataframe import dataframefrom marimo._plugins.ui._impl.dictionary import dictionary-from marimo._plugins.ui._impl.from_anywidget import _anywidget as anywidget+from marimo._plugins.ui._impl.from_anywidget import anywidgetfrom marimo._plugins.ui._impl.input import (button,checkbox,diff --git a/marimo/_plugins/ui/_impl/from_anywidget.py b/marimo/_plugins/ui/_impl/from_anywidget.pyindex aac7fdc19a..8fc7c21675 100644--- a/marimo/_plugins/ui/_impl/from_anywidget.py+++ b/marimo/_plugins/ui/_impl/from_anywidget.py@@ -7,17 +7,20 @@ from marimo._output.rich_help import mddocfrom marimo._plugins.ui._core.ui_element import UIElementif TYPE_CHECKING:- import anywidget # type: ignore [import-not-found, unused-ignore]+ from anywidget import ( # type: ignore [import-not-found,unused-ignore] # noqa: E501+ AnyWidget,+ )+# Weak dictionary# When the widget is deleted, the UIElement will be deleted as well-cache: Dict[Any, UIElement[Any, Any]] = weakref.WeakKeyDictionary() # type: ignore[no-untyped-call, unused-ignore, assignment]+cache: Dict[Any, UIElement[Any, Any]] = weakref.WeakKeyDictionary() # type: ignore[no-untyped-call, unused-ignore, assignment] # noqa: E501-def from_anywidget(widget: "anywidget.AnyWidget") -> UIElement[Any, Any]:+def from_anywidget(widget: "AnyWidget") -> UIElement[Any, Any]:"""Create a UIElement from an AnyWidget."""if widget not in cache:- cache[widget] = _anywidget(widget) # type: ignore[no-untyped-call, unused-ignore, assignment]+ cache[widget] = anywidget(widget) # type: ignore[no-untyped-call, unused-ignore, assignment]return cache[widget]@@ -25,7 +28,7 @@ T = Dict[str, Any]@mddoc-class _anywidget(UIElement[T, T]):+class anywidget(UIElement[T, T]):"""Create a UIElement from an AnyWidget.@@ -51,7 +54,7 @@ class _anywidget(UIElement[T, T]):- `widget`: The widget to wrap."""- def __init__(self, widget: "anywidget.AnyWidget"):+ def __init__(self, widget: "AnyWidget"):self.widget = widget# Get all the traits of the widgetdiff --git a/marimo/_server/models/completion.py b/marimo/_server/models/completion.pyindex 5c193185ce..61e380e0fb 100644--- a/marimo/_server/models/completion.py+++ b/marimo/_server/models/completion.py@@ -1,3 +1,4 @@+# Copyright 2024 Marimo. All rights reserved.from dataclasses import dataclassdiff --git a/marimo/_smoke_tests/carousel.py b/marimo/_smoke_tests/carousel.pyindex 64a3963744..248156bade 100644--- a/marimo/_smoke_tests/carousel.py+++ b/marimo/_smoke_tests/carousel.py@@ -1,3 +1,4 @@+# Copyright 2024 Marimo. All rights reserved.import marimo__generated_with = "0.2.13"diff --git a/tests/_plugins/ui/_impl/test_anywidget.py b/tests/_plugins/ui/_impl/test_anywidget.pyindex 6a17e6b69d..cf95c684a0 100644--- a/tests/_plugins/ui/_impl/test_anywidget.py+++ b/tests/_plugins/ui/_impl/test_anywidget.py@@ -4,17 +4,17 @@ from __future__ import annotationsimport pytestfrom marimo._dependencies.dependencies import DependencyManager-from marimo._plugins.ui._impl.from_anywidget import _anywidget+from marimo._plugins.ui._impl.from_anywidget import anywidgetfrom marimo._runtime.runtime import Kernelfrom tests.conftest import ExecReqProviderHAS_DEPS = DependencyManager.has_anywidget()if HAS_DEPS:- import anywidget+ import anywidget as _anywidgetimport traitlets- class CounterWidget(anywidget.AnyWidget):+ class CounterWidget(_anywidget.AnyWidget):_esm = """function render({ model, el }) {let getCount = () => model.get("count");@@ -32,7 +32,7 @@ if HAS_DEPS:class TestAnywidget:@staticmethodasync def test_instances(k: Kernel, exec_req: ExecReqProvider) -> None:- import anywidget+ import anywidget as _anywidgetawait k.run([@@ -66,7 +66,7 @@ as_marimo_element = mo.ui.anywidget(base_widget))assert k.globals["are_same"] is Trueassert k.globals["are_different"] is True- assert isinstance(k.globals["base_widget"], anywidget.AnyWidget)+ assert isinstance(k.globals["base_widget"], _anywidget.AnyWidget)assert "marimo-anywidget" in k.globals["as_marimo_element"].text@staticmethod@@ -105,5 +105,5 @@ as_marimo_element = mo.ui.anywidget(base_widget)),])- assert isinstance(k.globals["w"], _anywidget)+ assert isinstance(k.globals["w"], anywidget)assert k.globals["w_value"]["count"] == 10