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
refactor: migrate UIElementId to use NewType (#3843)
devin-ai-integration[bot]ebc52d3a13ec
diff --git a/marimo/_plugins/ui/_core/registry.py b/marimo/_plugins/ui/_core/registry.pyindex 10acf292b6..e26858a759 100644--- a/marimo/_plugins/ui/_core/registry.py+++ b/marimo/_plugins/ui/_core/registry.py@@ -15,9 +15,7 @@ else:from marimo._ast.app import _Namespacefrom marimo._plugins.ui._core.ui_element import UIElementfrom marimo._runtime.context import get_context-from marimo._types.ids import CellId_t--UIElementId = str+from marimo._types.ids import CellId_t, UIElementIdT = TypeVar("T")@@ -136,7 +134,7 @@ class UIElementRegistry:def resolve_lens(self, object_id: UIElementId, value: LensValue[T]- ) -> tuple[str, LensValue[T]]:+ ) -> tuple[UIElementId, LensValue[T]]:"""Resolve a lens, if any, to an object id and value updateReturns (resolved object id, resolved value)diff --git a/marimo/_plugins/ui/_core/ui_element.py b/marimo/_plugins/ui/_core/ui_element.pyindex fa91dbf62a..b1742c3fc6 100644--- a/marimo/_plugins/ui/_core/ui_element.py+++ b/marimo/_plugins/ui/_core/ui_element.py@@ -34,6 +34,7 @@ from marimo._runtime.context import (get_context,)from marimo._runtime.functions import Function+from marimo._types.ids import UIElementIdif TYPE_CHECKING:from marimo._plugins.ui._impl.input import form as form_plugin@@ -64,7 +65,7 @@ class Lens:id of its parent UI element, and the key at which its parent stores it."""- parent_id: str+ parent_id: UIElementIdkey: str@@ -214,9 +215,9 @@ class UIElement(Html, Generic[S, T], metaclass=abc.ABCMeta):# created by each cell is deterministic; this fact is used to# optionally override the element's initial value.try:- self._id = get_context().take_id()+ self._id = UIElementId(get_context().take_id())except (ids.NoIDProviderException, ContextNotInitializedError):- self._id = self._random_id+ self._id = UIElementId(self._random_id)self._ctx: RuntimeContext | Nonetry:diff --git a/marimo/_runtime/requests.py b/marimo/_runtime/requests.pyindex ce93549abb..4f4faf54a4 100644--- a/marimo/_runtime/requests.py+++ b/marimo/_runtime/requests.py@@ -20,13 +20,12 @@ from uuid import uuid4from marimo._config.config import MarimoConfigfrom marimo._data.models import DataTableSource-from marimo._types.ids import CellId_t+from marimo._types.ids import CellId_t, UIElementIdif TYPE_CHECKING:from starlette.datastructures import URLfrom starlette.requests import HTTPConnection-UIElementId = strCompletionRequestId = strFunctionCallId = strdiff --git a/marimo/_runtime/runtime.py b/marimo/_runtime/runtime.pyindex 24d7a40994..c1d4e30895 100644--- a/marimo/_runtime/runtime.py+++ b/marimo/_runtime/runtime.py@@ -136,7 +136,7 @@ from marimo._runtime.win32_interrupt_handler import Win32InterruptHandlerfrom marimo._server.model import SessionModefrom marimo._server.types import QueueTypefrom marimo._tracer import kernel_tracer-from marimo._types.ids import CellId_t+from marimo._types.ids import CellId_t, UIElementIdfrom marimo._utils.assert_never import assert_neverfrom marimo._utils.platform import is_pyodidefrom marimo._utils.signals import restore_signals@@ -1614,7 +1614,7 @@ class Kernel:# interacting with a view triggers reactive execution through the# source (parent).ctx = get_context()- resolved_requests: dict[str, Any] = {}+ resolved_requests: dict[UIElementId, Any] = {}referring_cells: set[CellId_t] = set()ui_element_registry = ctx.ui_element_registryfor object_id, value in request.ids_and_values:diff --git a/marimo/_runtime/utils/set_ui_element_request_manager.py b/marimo/_runtime/utils/set_ui_element_request_manager.pyindex 6f315a92fc..0eebb1fc29 100644--- a/marimo/_runtime/utils/set_ui_element_request_manager.py+++ b/marimo/_runtime/utils/set_ui_element_request_manager.py@@ -3,9 +3,9 @@ from __future__ import annotationsfrom typing import TYPE_CHECKING, Any-from marimo._plugins.ui._core.registry import UIElementIdfrom marimo._runtime.requests import SetUIElementValueRequestfrom marimo._server.types import QueueType+from marimo._types.ids import UIElementIdif TYPE_CHECKING:import asynciodiff --git a/marimo/_types/ids.py b/marimo/_types/ids.pyindex 08493ec738..9329f8b208 100644--- a/marimo/_types/ids.py+++ b/marimo/_types/ids.py@@ -6,8 +6,7 @@ from typing import NewType# CellId_t = NewType("CellId_t", str)CellId_t = str-# UIElementId = NewType("UIElementId", str)-UIElementId = str+UIElementId = NewType("UIElementId", str)SessionId = NewType("SessionId", str)