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.

chore: _anywidget -> anywidget (#912)

Akshay Agrawalb8ce1be4559d
diff --git a/docs/api/inputs/anywidget.md b/docs/api/inputs/anywidget.md
index 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__.py
index 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 batch
from marimo._plugins.ui._impl.data_explorer import data_explorer
from marimo._plugins.ui._impl.dataframes.dataframe import dataframe
from 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 anywidget
from 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.py
index 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 mddoc
from marimo._plugins.ui._core.ui_element import UIElement
if 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 widget
diff --git a/marimo/_server/models/completion.py b/marimo/_server/models/completion.py
index 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 dataclass
diff --git a/marimo/_smoke_tests/carousel.py b/marimo/_smoke_tests/carousel.py
index 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.py
index 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 annotations
import pytest
from marimo._dependencies.dependencies import DependencyManager
-from marimo._plugins.ui._impl.from_anywidget import _anywidget
+from marimo._plugins.ui._impl.from_anywidget import anywidget
from marimo._runtime.runtime import Kernel
from tests.conftest import ExecReqProvider
HAS_DEPS = DependencyManager.has_anywidget()
if HAS_DEPS:
- import anywidget
+ import anywidget as _anywidget
import 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:
@staticmethod
async def test_instances(k: Kernel, exec_req: ExecReqProvider) -> None:
- import anywidget
+ import anywidget as _anywidget
await k.run(
[
@@ -66,7 +66,7 @@ as_marimo_element = mo.ui.anywidget(base_widget)
)
assert k.globals["are_same"] is True
assert 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