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: move ids to central file (#3839)
Myles Scolnick97bf1a38da0d
diff --git a/marimo/_ast/app.py b/marimo/_ast/app.pyindex f43e73f7c2..be5c8d61d7 100644--- a/marimo/_ast/app.py+++ b/marimo/_ast/app.py@@ -26,13 +26,15 @@ from typing import ()from uuid import uuid4+from marimo._types.ids import CellId_t+if sys.version_info < (3, 10):from typing_extensions import ParamSpec, TypeAliaselse:from typing import ParamSpec, TypeAliasfrom marimo import _loggers-from marimo._ast.cell import Cell, CellConfig, CellId_t, CellImpl+from marimo._ast.cell import Cell, CellConfig, CellImplfrom marimo._ast.cell_manager import CellManagerfrom marimo._ast.errors import (CycleError,diff --git a/marimo/_ast/cell.py b/marimo/_ast/cell.pyindex 68884a36ef..a97ba2977f 100644--- a/marimo/_ast/cell.py+++ b/marimo/_ast/cell.py@@ -11,10 +11,9 @@ from typing import TYPE_CHECKING, Any, Literal, Mapping, Optionalfrom marimo._ast.sql_visitor import SQLVisitorfrom marimo._ast.visitor import ImportData, Language, Name, VariableDatafrom marimo._runtime.exceptions import MarimoRuntimeException+from marimo._types.ids import CellId_tfrom marimo._utils.deep_merge import deep_merge-CellId_t = str-if TYPE_CHECKING:from collections.abc import Iterablefrom types import CodeTypediff --git a/marimo/_ast/cell_manager.py b/marimo/_ast/cell_manager.pyindex 060dc9d185..ad0edbb5d0 100644--- a/marimo/_ast/cell_manager.py+++ b/marimo/_ast/cell_manager.py@@ -19,11 +19,12 @@ if sys.version_info < (3, 10):else:from typing import ParamSpec, TypeAlias-from marimo._ast.cell import Cell, CellConfig, CellId_t+from marimo._ast.cell import Cell, CellConfigfrom marimo._ast.compiler import cell_factory, toplevel_cell_factoryfrom marimo._ast.models import CellDatafrom marimo._ast.names import DEFAULT_CELL_NAMEfrom marimo._ast.pytest import wrap_fn_for_pytest+from marimo._types.ids import CellId_tif TYPE_CHECKING:from marimo._ast.app import InternalApp@@ -75,8 +76,8 @@ class CellManager:_id = self.prefix + "".join(self.random_seed.choices(string.ascii_letters, k=4))- self.seen_ids.add(_id)- return _id+ self.seen_ids.add(CellId_t(_id))+ return CellId_t(_id)# TODO: maybe remove this, it is leakydef cell_decorator(diff --git a/marimo/_ast/compiler.py b/marimo/_ast/compiler.pyindex b92e284e76..8fe6ee996c 100644--- a/marimo/_ast/compiler.py+++ b/marimo/_ast/compiler.py@@ -15,13 +15,13 @@ from typing import TYPE_CHECKING, Any, Callable, Optionalfrom marimo import _loggersfrom marimo._ast.cell import (Cell,- CellId_t,CellImpl,ImportWorkspace,SourcePosition,)from marimo._ast.variables import is_localfrom marimo._ast.visitor import ImportData, Name, ScopedVisitor+from marimo._types.ids import CellId_tfrom marimo._utils.tmpdir import get_tmpdirLOGGER = _loggers.marimo_logger()@@ -38,7 +38,7 @@ def cell_id_from_filename(filename: str) -> Optional[CellId_t]:"""Parse cell id from filename."""matches = re.findall(r"__marimo__cell_(.*?)_", filename)if matches:- return str(matches[0])+ return CellId_t(matches[0])return Nonediff --git a/marimo/_ast/models.py b/marimo/_ast/models.pyindex 1795c11531..b15ca24e13 100644--- a/marimo/_ast/models.py+++ b/marimo/_ast/models.py@@ -4,7 +4,8 @@ from __future__ import annotationsfrom dataclasses import dataclassfrom typing import Optional-from marimo._ast.cell import Cell, CellConfig, CellId_t+from marimo._ast.cell import Cell, CellConfig+from marimo._types.ids import CellId_t@dataclassdiff --git a/marimo/_ast/variables.py b/marimo/_ast/variables.pyindex e5be8e2dc4..df95ad2dbe 100644--- a/marimo/_ast/variables.py+++ b/marimo/_ast/variables.py@@ -2,16 +2,15 @@from __future__ import annotationsimport re-from typing import TYPE_CHECKING, Optional--if TYPE_CHECKING:- from marimo._ast.cell import CellId_t--from collections import namedtuple+from typing import Optional++from marimo._types.ids import CellId_tUnmagledLocal = namedtuple("UnmagledLocal", "name cell")+_EMPTY_CELL_ID = CellId_t("")+def if_local_then_mangle(ref: str, cell_id: CellId_t) -> str:if is_local(ref):@@ -21,7 +20,9 @@ def if_local_then_mangle(ref: str, cell_id: CellId_t) -> str:return ref-def unmangle_local(name: str, cell_id: CellId_t = "") -> UnmagledLocal:+def unmangle_local(+ name: str, cell_id: CellId_t = _EMPTY_CELL_ID+) -> UnmagledLocal:if not is_mangled_local(name, cell_id):return UnmagledLocal(name, "")private_prefix = r"^_cell_\w+?_"@@ -30,7 +31,7 @@ def unmangle_local(name: str, cell_id: CellId_t = "") -> UnmagledLocal:return UnmagledLocal(re.sub(private_prefix, "_", name), name.split("_")[2])-def is_mangled_local(name: str, cell_id: CellId_t = "") -> bool:+def is_mangled_local(name: str, cell_id: CellId_t = _EMPTY_CELL_ID) -> bool:return name.startswith(f"_cell_{cell_id}")@@ -39,7 +40,7 @@ def is_local(name: str) -> bool:def get_cell_from_local(- name: str, cell_id: CellId_t = ""+ name: str, cell_id: CellId_t = _EMPTY_CELL_ID) -> Optional[CellId_t]:local = unmangle_local(if_local_then_mangle(name, cell_id)).cellreturn local if local else Nonediff --git a/marimo/_data/models.py b/marimo/_data/models.pyindex 17fe24f532..e1a6229870 100644--- a/marimo/_data/models.py+++ b/marimo/_data/models.py@@ -6,6 +6,8 @@ from datetime import date, datetime, time, timedelta # noqa: TCH003from decimal import Decimalfrom typing import Any, List, Literal, Optional, Union+from marimo._types.ids import VariableName+DataType = Literal["string","boolean",@@ -39,8 +41,6 @@ class DataTableColumn:DataTableSource = Literal["local", "duckdb", "connection"]-VariableName = str-@dataclassclass DataTable:diff --git a/marimo/_messaging/console_output_worker.py b/marimo/_messaging/console_output_worker.pyindex 7f77ba8909..f2a5bc4eee 100644--- a/marimo/_messaging/console_output_worker.py+++ b/marimo/_messaging/console_output_worker.py@@ -5,9 +5,9 @@ import timefrom dataclasses import dataclassfrom typing import TYPE_CHECKING, Literal-from marimo._ast.cell import CellId_tfrom marimo._messaging.cell_output import CellChannel, CellOutputfrom marimo._messaging.mimetypes import KnownMimeType+from marimo._types.ids import CellId_tif TYPE_CHECKING:from collections import dequediff --git a/marimo/_messaging/errors.py b/marimo/_messaging/errors.pyindex d6e9ff6aac..5db59fdc50 100644--- a/marimo/_messaging/errors.py+++ b/marimo/_messaging/errors.py@@ -4,8 +4,8 @@ from __future__ import annotationsfrom dataclasses import dataclassfrom typing import Literal, Optional, Union-from marimo._ast.cell import CellId_tfrom marimo._runtime.dataflow import EdgeWithVar+from marimo._types.ids import CellId_t@dataclassdiff --git a/marimo/_messaging/ops.py b/marimo/_messaging/ops.pyindex d3c4dc2b07..94af517f5d 100644--- a/marimo/_messaging/ops.py+++ b/marimo/_messaging/ops.py@@ -27,7 +27,7 @@ from uuid import uuid4from marimo import _loggers as loggersfrom marimo._ast.app import _AppConfig-from marimo._ast.cell import CellConfig, CellId_t, RuntimeStateType+from marimo._ast.cell import CellConfig, RuntimeStateTypefrom marimo._data.models import (ColumnSummary,DataSourceConnection,@@ -54,6 +54,7 @@ from marimo._plugins.ui._core.ui_element import UIElementfrom marimo._runtime.context import get_contextfrom marimo._runtime.context.utils import get_modefrom marimo._runtime.layout.layout import LayoutConfig+from marimo._types.ids import CellId_tfrom marimo._utils.platform import is_pyodide, is_windowsLOGGER = loggers.marimo_logger()diff --git a/marimo/_messaging/streams.py b/marimo/_messaging/streams.pyindex 5da2fb4f51..201b146e7e 100644--- a/marimo/_messaging/streams.py+++ b/marimo/_messaging/streams.py@@ -17,7 +17,6 @@ from typing import ()from marimo import _loggers-from marimo._ast.cell import CellId_tfrom marimo._messaging.cell_output import CellChannelfrom marimo._messaging.console_output_worker import ConsoleMsg, buffered_writerfrom marimo._messaging.mimetypes import KnownMimeType@@ -29,6 +28,7 @@ from marimo._messaging.types import (Stream,)from marimo._server.types import QueueType+from marimo._types.ids import CellId_tif TYPE_CHECKING:import queuediff --git a/marimo/_messaging/types.py b/marimo/_messaging/types.pyindex 11d48ca08b..6ee3c78f32 100644--- a/marimo/_messaging/types.py+++ b/marimo/_messaging/types.py@@ -1,10 +1,12 @@# Copyright 2024 Marimo. All rights reserved.+from __future__ import annotations+import abcimport iofrom typing import Any, Dict, Optional, Tuple-from marimo._ast.cell import CellId_tfrom marimo._messaging.mimetypes import KnownMimeType+from marimo._types.ids import CellId_t# The message from the kernel is a tuple of message type# and a json representation of the messagediff --git a/marimo/_plugins/ui/_core/registry.py b/marimo/_plugins/ui/_core/registry.pyindex de0b64d2a4..10acf292b6 100644--- a/marimo/_plugins/ui/_core/registry.py+++ b/marimo/_plugins/ui/_core/registry.py@@ -13,9 +13,9 @@ else:from typing import TypeAliasfrom marimo._ast.app import _Namespace-from marimo._ast.cell import CellId_tfrom marimo._plugins.ui._core.ui_element import UIElementfrom marimo._runtime.context import get_context+from marimo._types.ids import CellId_tUIElementId = strdiff --git a/marimo/_pyodide/pyodide_session.py b/marimo/_pyodide/pyodide_session.pyindex 41f6a81cba..184cf1945f 100644--- a/marimo/_pyodide/pyodide_session.py+++ b/marimo/_pyodide/pyodide_session.py@@ -9,7 +9,7 @@ import signalfrom typing import Any, Callable, Optionalfrom marimo import _loggers-from marimo._ast.cell import CellConfig, CellId_t+from marimo._ast.cell import CellConfigfrom marimo._config.config import MarimoConfigfrom marimo._messaging.types import KernelMessagefrom marimo._pyodide.streams import (@@ -62,6 +62,7 @@ from marimo._server.models.models import ()from marimo._server.session.session_view import SessionViewfrom marimo._snippets.snippets import read_snippets+from marimo._types.ids import CellId_tfrom marimo._utils.case import deep_to_camel_casefrom marimo._utils.formatter import DefaultFormatterfrom marimo._utils.parse_dataclass import parse_rawdiff --git a/marimo/_pyodide/streams.py b/marimo/_pyodide/streams.pyindex 6327362629..e0b2085318 100644--- a/marimo/_pyodide/streams.py+++ b/marimo/_pyodide/streams.py@@ -6,7 +6,6 @@ import sysfrom typing import Any, Callable, Iterable, Optionalfrom marimo import _loggers-from marimo._ast.cell import CellId_tfrom marimo._messaging.cell_output import CellChannel, CellOutputfrom marimo._messaging.mimetypes import KnownMimeTypefrom marimo._messaging.ops import CellOp@@ -18,6 +17,7 @@ from marimo._messaging.types import (Stdout,Stream,)+from marimo._types.ids import CellId_tLOGGER = _loggers.marimo_logger()diff --git a/marimo/_runtime/app/common.py b/marimo/_runtime/app/common.pyindex 9378ebdc41..0b2a222902 100644--- a/marimo/_runtime/app/common.py+++ b/marimo/_runtime/app/common.py@@ -3,7 +3,7 @@ from __future__ import annotationsfrom typing import Any, Dict, Tuple-from marimo._ast.cell import CellId_t+from marimo._types.ids import CellId_tOutputsType = Dict[CellId_t, Any]DefsType = Dict[str, Any]diff --git a/marimo/_runtime/app/kernel_runner.py b/marimo/_runtime/app/kernel_runner.pyindex 0e05d89d9d..6f8a2e0e2d 100644--- a/marimo/_runtime/app/kernel_runner.py+++ b/marimo/_runtime/app/kernel_runner.py@@ -4,7 +4,7 @@ from __future__ import annotationsimport weakreffrom typing import TYPE_CHECKING, Any-from marimo._ast.cell import CellId_t, CellImpl+from marimo._ast.cell import CellImplfrom marimo._config.config import DEFAULT_CONFIGfrom marimo._runtime.app.common import RunOutputfrom marimo._runtime.context.types import get_context@@ -17,6 +17,7 @@ from marimo._runtime.requests import ()from marimo._runtime.runner import cell_runnerfrom marimo._server.model import SessionMode+from marimo._types.ids import CellId_tif TYPE_CHECKING:from marimo._ast.app import InternalApp@@ -38,7 +39,7 @@ class AppKernelRunner:from marimo._runtime.runtime import Kernelself.app = app- self._outputs: dict[str, Any] = {}+ self._outputs: dict[CellId_t, Any] = {}ctx = get_context()if not isinstance(ctx, KernelRuntimeContext):diff --git a/marimo/_runtime/app/script_runner.py b/marimo/_runtime/app/script_runner.pyindex 82b4a3003a..de60866322 100644--- a/marimo/_runtime/app/script_runner.py+++ b/marimo/_runtime/app/script_runner.py@@ -4,7 +4,7 @@ from __future__ import annotationsimport asynciofrom typing import TYPE_CHECKING, Any, Callable, Iterator-from marimo._ast.cell import CellId_t, CellImpl+from marimo._ast.cell import CellImplfrom marimo._dependencies.dependencies import DependencyManagerfrom marimo._messaging.types import NoopStreamfrom marimo._runtime.app.common import RunOutput@@ -25,6 +25,7 @@ from marimo._runtime.patches import (create_main_module,patch_main_module_context,)+from marimo._types.ids import CellId_tif TYPE_CHECKING:from marimo._ast.app import InternalAppdiff --git a/marimo/_runtime/cell_lifecycle_registry.py b/marimo/_runtime/cell_lifecycle_registry.pyindex 0491b99542..5086fe84ee 100644--- a/marimo/_runtime/cell_lifecycle_registry.py+++ b/marimo/_runtime/cell_lifecycle_registry.py@@ -3,8 +3,8 @@ from __future__ import annotationsimport dataclasses-from marimo._ast.cell import CellId_tfrom marimo._runtime.cell_lifecycle_item import CellLifecycleItem+from marimo._types.ids import CellId_t@dataclasses.dataclassdiff --git a/marimo/_runtime/context/kernel_context.py b/marimo/_runtime/context/kernel_context.pyindex 428428b545..c7125c1e6d 100644--- a/marimo/_runtime/context/kernel_context.py+++ b/marimo/_runtime/context/kernel_context.py@@ -22,10 +22,10 @@ from marimo._server.model import SessionModeif TYPE_CHECKING:from marimo._ast.app import InternalApp- from marimo._ast.cell import CellId_tfrom marimo._messaging.types import Streamfrom marimo._runtime.runtime import Kernelfrom marimo._runtime.state import State+ from marimo._types.ids import CellId_t@dataclassdiff --git a/marimo/_runtime/context/script_context.py b/marimo/_runtime/context/script_context.pyindex 5794652356..cb0417492a 100644--- a/marimo/_runtime/context/script_context.py+++ b/marimo/_runtime/context/script_context.py@@ -29,8 +29,8 @@ from marimo._runtime.state import State, StateRegistryif TYPE_CHECKING:from marimo._ast.app import InternalApp- from marimo._ast.cell import CellId_tfrom marimo._messaging.types import Stream+ from marimo._types.ids import CellId_t@dataclassdiff --git a/marimo/_runtime/context/types.py b/marimo/_runtime/context/types.pyindex 8fd172772f..a9f2de1083 100644--- a/marimo/_runtime/context/types.py+++ b/marimo/_runtime/context/types.py@@ -22,13 +22,13 @@ from marimo._runtime.requests import HTTPRequestif TYPE_CHECKING:from marimo._ast.app import AppKernelRunnerRegistry, InternalApp- from marimo._ast.cell import CellId_tfrom marimo._messaging.types import Streamfrom marimo._output.hypertext import Htmlfrom marimo._plugins.ui._core.registry import UIElementRegistryfrom marimo._runtime.params import CLIArgs, QueryParamsfrom marimo._runtime.state import State, StateRegistryfrom marimo._runtime.virtual_file import VirtualFileRegistry+ from marimo._types.ids import CellId_tclass GlobalContext:diff --git a/marimo/_runtime/dataflow.py b/marimo/_runtime/dataflow.pyindex 65522f9321..b02c066296 100644--- a/marimo/_runtime/dataflow.py+++ b/marimo/_runtime/dataflow.py@@ -7,13 +7,13 @@ from typing import TYPE_CHECKING, Any, Callable, List, Literal, Optional, Tuplefrom marimo import _loggersfrom marimo._ast.cell import (- CellId_t,CellImpl,)from marimo._ast.compiler import code_keyfrom marimo._ast.variables import is_mangled_localfrom marimo._ast.visitor import ImportData, Name, VariableDatafrom marimo._runtime.executor import execute_cell, execute_cell_async+from marimo._types.ids import CellId_tif TYPE_CHECKING:from collections.abc import Collectiondiff --git a/marimo/_runtime/functions.py b/marimo/_runtime/functions.pyindex 9113ab8606..649e9eb4cf 100644--- a/marimo/_runtime/functions.py+++ b/marimo/_runtime/functions.py@@ -6,8 +6,8 @@ from __future__ import annotationsimport dataclassesfrom typing import Any, Callable, Coroutine, Generic, Type, TypeVar-from marimo._ast.cell import CellId_tfrom marimo._loggers import marimo_logger+from marimo._types.ids import CellId_tfrom marimo._utils.parse_dataclass import parse_rawLOGGER = marimo_logger()diff --git a/marimo/_runtime/output/_output.py b/marimo/_runtime/output/_output.pyindex 462bd0def8..7c2d38e826 100644--- a/marimo/_runtime/output/_output.py+++ b/marimo/_runtime/output/_output.py@@ -1,7 +1,6 @@# Copyright 2024 Marimo. All rights reserved.from __future__ import annotations-from marimo._ast.cell import CellId_tfrom marimo._messaging.cell_output import CellChannelfrom marimo._messaging.ops import CellOpfrom marimo._messaging.tracebacks import write_traceback@@ -10,6 +9,7 @@ from marimo._output.rich_help import mddocfrom marimo._plugins.stateless.flex import vstackfrom marimo._runtime.context import get_contextfrom marimo._runtime.context.types import ContextNotInitializedError+from marimo._types.ids import CellId_tdef write_internal(cell_id: CellId_t, value: object) -> None:diff --git a/marimo/_runtime/packages/module_registry.py b/marimo/_runtime/packages/module_registry.pyindex f45319a758..9c41a301ac 100644--- a/marimo/_runtime/packages/module_registry.py+++ b/marimo/_runtime/packages/module_registry.py@@ -4,8 +4,8 @@ from __future__ import annotationsimport importlib.utilimport sys-from marimo._ast.cell import CellId_tfrom marimo._runtime.dataflow import DirectedGraph+from marimo._types.ids import CellId_tdef _is_module_installed(module_name: str) -> bool:diff --git a/marimo/_runtime/redirect_streams.py b/marimo/_runtime/redirect_streams.pyindex ec67a2c870..82be28d42c 100644--- a/marimo/_runtime/redirect_streams.py+++ b/marimo/_runtime/redirect_streams.py@@ -6,11 +6,11 @@ import osimport sysfrom typing import Iterator-from marimo._ast.cell import CellId_tfrom marimo._messaging.streams import (redirect,)from marimo._messaging.types import Stderr, Stdin, Stdout, Stream+from marimo._types.ids import CellId_tdef forward_os_stream(stream_object: Stdout | Stderr, fd: int) -> None:diff --git a/marimo/_runtime/reload/module_watcher.py b/marimo/_runtime/reload/module_watcher.pyindex 7c6527ded5..41d10e7d5e 100644--- a/marimo/_runtime/reload/module_watcher.py+++ b/marimo/_runtime/reload/module_watcher.py@@ -19,7 +19,7 @@ from marimo._runtime.reload.autoreload import (if TYPE_CHECKING:import types- from marimo._ast.cell import CellId_t+ from marimo._types.ids import CellId_tLOGGER = _loggers.marimo_logger()diff --git a/marimo/_runtime/requests.py b/marimo/_runtime/requests.pyindex 26e01dac35..ce93549abb 100644--- a/marimo/_runtime/requests.py+++ b/marimo/_runtime/requests.py@@ -18,9 +18,9 @@ from typing import ()from uuid import uuid4-from marimo._ast.cell import CellId_tfrom marimo._config.config import MarimoConfigfrom marimo._data.models import DataTableSource+from marimo._types.ids import CellId_tif TYPE_CHECKING:from starlette.datastructures import URLdiff --git a/marimo/_runtime/runner/cell_runner.py b/marimo/_runtime/runner/cell_runner.pyindex 4d59ed81a2..9f65887d2c 100644--- a/marimo/_runtime/runner/cell_runner.py+++ b/marimo/_runtime/runner/cell_runner.py@@ -11,7 +11,7 @@ import tracebackfrom dataclasses import dataclassfrom typing import TYPE_CHECKING, Any, Callable, Iterator, Optional, Union-from marimo._ast.cell import CellId_t, CellImpl+from marimo._ast.cell import CellImplfrom marimo._ast.variables import unmangle_localfrom marimo._config.config import ExecutionType, OnCellChangeTypefrom marimo._loggers import marimo_logger@@ -34,6 +34,7 @@ from marimo._runtime.executor import (execute_cell_async,)from marimo._runtime.marimo_pdb import MarimoPdb+from marimo._types.ids import CellId_tLOGGER = marimo_logger()diff --git a/marimo/_runtime/runtime.py b/marimo/_runtime/runtime.pyindex 510803e3cc..24d7a40994 100644--- a/marimo/_runtime/runtime.py+++ b/marimo/_runtime/runtime.py@@ -20,7 +20,7 @@ from typing import TYPE_CHECKING, Any, Callable, Iterator, List, Optional, castfrom uuid import uuid4from marimo import _loggers-from marimo._ast.cell import CellConfig, CellId_t, CellImpl+from marimo._ast.cell import CellConfig, CellImplfrom marimo._ast.compiler import compile_cellfrom marimo._ast.variables import is_localfrom marimo._ast.visitor import ImportData, Name, VariableData@@ -136,6 +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_tfrom marimo._utils.assert_never import assert_neverfrom marimo._utils.platform import is_pyodidefrom marimo._utils.signals import restore_signalsdiff --git a/marimo/_runtime/scratch.py b/marimo/_runtime/scratch.pyindex 13cf16b97c..30915ce676 100644--- a/marimo/_runtime/scratch.py+++ b/marimo/_runtime/scratch.py@@ -1,6 +1,6 @@# Copyright 2024 Marimo. All rights reserved.from __future__ import annotations-from marimo._ast.cell import CellId_t+from marimo._types.ids import CellId_t-SCRATCH_CELL_ID: CellId_t = "__scratch__"+SCRATCH_CELL_ID = CellId_t("__scratch__")diff --git a/marimo/_runtime/validate_graph.py b/marimo/_runtime/validate_graph.pyindex cdbe7deeb2..2adc25c155 100644--- a/marimo/_runtime/validate_graph.py+++ b/marimo/_runtime/validate_graph.py@@ -4,7 +4,6 @@ from __future__ import annotationsimport itertoolsfrom collections import defaultdict-from marimo._ast.cell import CellId_tfrom marimo._messaging.errors import (CycleError,DeleteNonlocalError,@@ -12,6 +11,7 @@ from marimo._messaging.errors import (MultipleDefinitionError,)from marimo._runtime.dataflow import DirectedGraph+from marimo._types.ids import CellId_tdef check_for_multiple_definitions(diff --git a/marimo/_save/hash.py b/marimo/_save/hash.pyindex 70262df350..605ba10a76 100644--- a/marimo/_save/hash.py+++ b/marimo/_save/hash.py@@ -29,11 +29,12 @@ from marimo._runtime.primitives import (from marimo._runtime.state import SetFunctor, Statefrom marimo._save.ast import DeprivateVisitor, strip_functionfrom marimo._save.cache import Cache, CacheType+from marimo._types.ids import CellId_tif TYPE_CHECKING:from types import CodeType- from marimo._ast.cell import CellId_t, CellImpl+ from marimo._ast.cell import CellImplfrom marimo._runtime.context.types import RuntimeContextfrom marimo._runtime.dataflow import DirectedGraphfrom marimo._save.loaders import Loaderdiff --git a/marimo/_server/api/deps.py b/marimo/_server/api/deps.pyindex 4bee745744..ca365f0f85 100644--- a/marimo/_server/api/deps.py+++ b/marimo/_server/api/deps.py@@ -5,10 +5,10 @@ from typing import TYPE_CHECKING, Any, Optional, Union, castfrom marimo import _loggers as loggersfrom marimo._config.manager import MarimoConfigManager-from marimo._server.ids import SessionIdfrom marimo._server.model import SessionModefrom marimo._server.sessions import Session, SessionManagerfrom marimo._server.tokens import SkewProtectionToken+from marimo._types.ids import SessionIdif TYPE_CHECKING:from starlette.applications import Starlettediff --git a/marimo/_server/api/endpoints/config.py b/marimo/_server/api/endpoints/config.pyindex 32b9a8f167..8909513876 100644--- a/marimo/_server/api/endpoints/config.py+++ b/marimo/_server/api/endpoints/config.py@@ -9,13 +9,13 @@ from marimo import _loggersfrom marimo._runtime.requests import SetUserConfigRequestfrom marimo._server.api.deps import AppStatefrom marimo._server.api.utils import parse_request-from marimo._server.ids import ConsumerIdfrom marimo._server.models.models import (BaseResponse,SaveUserConfigurationRequest,SuccessResponse,)from marimo._server.router import APIRouter+from marimo._types.ids import ConsumerIdif TYPE_CHECKING:from starlette.requests import Requestdiff --git a/marimo/_server/api/endpoints/datasources.py b/marimo/_server/api/endpoints/datasources.pyindex 4094399753..f26b536d48 100644--- a/marimo/_server/api/endpoints/datasources.py+++ b/marimo/_server/api/endpoints/datasources.py@@ -9,9 +9,9 @@ from marimo import _loggersfrom marimo._runtime.requests import PreviewDatasetColumnRequestfrom marimo._server.api.deps import AppStatefrom marimo._server.api.utils import parse_request-from marimo._server.ids import ConsumerIdfrom marimo._server.models.models import BaseResponse, SuccessResponsefrom marimo._server.router import APIRouter+from marimo._types.ids import ConsumerIdif TYPE_CHECKING:from starlette.requests import Requestdiff --git a/marimo/_server/api/endpoints/editing.py b/marimo/_server/api/endpoints/editing.pyindex 37fb249354..bc209eb236 100644--- a/marimo/_server/api/endpoints/editing.py+++ b/marimo/_server/api/endpoints/editing.py@@ -14,7 +14,6 @@ from marimo._runtime.requests import ()from marimo._server.api.deps import AppStatefrom marimo._server.api.utils import parse_request-from marimo._server.ids import ConsumerIdfrom marimo._server.models.models import (BaseResponse,FormatRequest,@@ -23,6 +22,7 @@ from marimo._server.models.models import (SuccessResponse,)from marimo._server.router import APIRouter+from marimo._types.ids import ConsumerIdfrom marimo._utils.formatter import DefaultFormatterif TYPE_CHECKING:diff --git a/marimo/_server/api/endpoints/execution.py b/marimo/_server/api/endpoints/execution.pyindex 3ee0f86fbc..7b208d21b1 100644--- a/marimo/_server/api/endpoints/execution.py+++ b/marimo/_server/api/endpoints/execution.py@@ -19,7 +19,6 @@ from marimo._server.api.deps import AppStatefrom marimo._server.api.endpoints.ws import FILE_QUERY_PARAM_KEYfrom marimo._server.api.utils import parse_requestfrom marimo._server.file_router import MarimoFileKey-from marimo._server.ids import ConsumerIdfrom marimo._server.models.models import (BaseResponse,InstantiateRequest,@@ -30,6 +29,7 @@ from marimo._server.models.models import ()from marimo._server.router import APIRouterfrom marimo._server.uvicorn_utils import close_uvicorn+from marimo._types.ids import ConsumerIdif TYPE_CHECKING:from starlette.requests import Requestdiff --git a/marimo/_server/api/endpoints/files.py b/marimo/_server/api/endpoints/files.pyindex ea749ba477..6d252dfe1d 100644--- a/marimo/_server/api/endpoints/files.py+++ b/marimo/_server/api/endpoints/files.py@@ -11,7 +11,6 @@ from marimo import _loggersfrom marimo._server.api.deps import AppStatefrom marimo._server.api.status import HTTPStatusfrom marimo._server.api.utils import parse_request-from marimo._server.ids import ConsumerIdfrom marimo._server.models.models import (BaseResponse,CopyNotebookRequest,@@ -22,6 +21,7 @@ from marimo._server.models.models import (SuccessResponse,)from marimo._server.router import APIRouter+from marimo._types.ids import ConsumerIdif TYPE_CHECKING:from starlette.requests import Requestdiff --git a/marimo/_server/api/endpoints/ws.py b/marimo/_server/api/endpoints/ws.pyindex bd2f2b504f..ce99ad47f0 100644--- a/marimo/_server/api/endpoints/ws.py+++ b/marimo/_server/api/endpoints/ws.py@@ -11,7 +11,7 @@ from typing import TYPE_CHECKING, Any, Callable, Optionalfrom starlette.websockets import WebSocket, WebSocketDisconnect, WebSocketStatefrom marimo import _loggers-from marimo._ast.cell import CellConfig, CellId_t+from marimo._ast.cell import CellConfigfrom marimo._cli.upgrade import check_for_updatesfrom marimo._config.settings import GLOBAL_SETTINGSfrom marimo._messaging.ops import (@@ -31,7 +31,6 @@ from marimo._plugins.core.web_component import JSONTypefrom marimo._runtime.params import QueryParamsfrom marimo._server.api.deps import AppStatefrom marimo._server.file_router import MarimoFileKey-from marimo._server.ids import ConsumerIdfrom marimo._server.model import (ConnectionState,SessionConsumer,@@ -39,6 +38,7 @@ from marimo._server.model import ()from marimo._server.router import APIRouterfrom marimo._server.sessions import Session, SessionManager+from marimo._types.ids import CellId_t, ConsumerIdif TYPE_CHECKING:from pycrdt import Doc, Text, TransactionEventdiff --git a/marimo/_server/errors.py b/marimo/_server/errors.pyindex 228f2ee3ae..9a37fd922c 100644--- a/marimo/_server/errors.py+++ b/marimo/_server/errors.py@@ -14,9 +14,9 @@ from marimo._server.api.status import (HTTPException as MarimoHTTPException,is_client_error,)-from marimo._server.ids import ConsumerIdfrom marimo._server.model import SessionModefrom marimo._server.sessions import send_message_to_consumer+from marimo._types.ids import ConsumerIdif TYPE_CHECKING:from starlette.requests import Requestdiff --git a/marimo/_server/export/__init__.py b/marimo/_server/export/__init__.pyindex c4010e8622..b9ab538245 100644--- a/marimo/_server/export/__init__.py+++ b/marimo/_server/export/__init__.py@@ -23,6 +23,7 @@ from marimo._server.model import ConnectionState, SessionConsumer, SessionModefrom marimo._server.models.export import ExportAsHTMLRequestfrom marimo._server.models.models import InstantiateRequestfrom marimo._server.session.session_view import SessionView+from marimo._types.ids import ConsumerIdfrom marimo._utils.marimo_path import MarimoPathfrom marimo._utils.parse_dataclass import parse_raw@@ -211,7 +212,7 @@ async def run_app_until_completion(class DefaultSessionConsumer(SessionConsumer):def __init__(self) -> None:self.did_error = False- super().__init__(consumer_id="default")+ super().__init__(consumer_id=ConsumerId("default"))def on_start(self,diff --git a/marimo/_server/file_manager.py b/marimo/_server/file_manager.pyindex 4174dbec64..e8a9979307 100644--- a/marimo/_server/file_manager.py+++ b/marimo/_server/file_manager.py@@ -9,7 +9,7 @@ from typing import Any, Dict, Optionalfrom marimo import _loggersfrom marimo._ast import codegenfrom marimo._ast.app import App, InternalApp, _AppConfig-from marimo._ast.cell import CellConfig, CellId_t+from marimo._ast.cell import CellConfigfrom marimo._config.config import WidthTypefrom marimo._runtime.layout.layout import (LayoutConfig,@@ -22,6 +22,7 @@ from marimo._server.models.models import (SaveNotebookRequest,)from marimo._server.utils import canonicalize_filename+from marimo._types.ids import CellId_tLOGGER = _loggers.marimo_logger()diff --git a/marimo/_server/ids.py b/marimo/_server/ids.pydeleted file mode 100644index e2a55e4f6c..0000000000--- a/marimo/_server/ids.py+++ /dev/null@@ -1,5 +0,0 @@-# Copyright 2024 Marimo. All rights reserved.-from __future__ import annotations--SessionId = str-ConsumerId = strdiff --git a/marimo/_server/model.py b/marimo/_server/model.pyindex 9fa5230883..9184151f2c 100644--- a/marimo/_server/model.py+++ b/marimo/_server/model.py@@ -5,7 +5,7 @@ import abcfrom enum import Enumfrom typing import TYPE_CHECKING, Callable-from marimo._server.ids import ConsumerId+from marimo._types.ids import ConsumerIdif TYPE_CHECKING:from marimo._messaging.ops import MessageOperationdiff --git a/marimo/_server/models/home.py b/marimo/_server/models/home.pyindex 3381b6737e..d86ae6ea24 100644--- a/marimo/_server/models/home.py+++ b/marimo/_server/models/home.py@@ -4,9 +4,9 @@ from __future__ import annotationsfrom dataclasses import dataclassfrom typing import List, Optional-from marimo._server.ids import SessionIdfrom marimo._server.models.files import FileInfofrom marimo._tutorials import Tutorial+from marimo._types.ids import SessionId@dataclassdiff --git a/marimo/_server/models/models.py b/marimo/_server/models/models.pyindex 15e893fae1..080a0c22a0 100644--- a/marimo/_server/models/models.py+++ b/marimo/_server/models/models.py@@ -5,7 +5,7 @@ import osfrom dataclasses import dataclassfrom typing import Any, Dict, List, Optional-from marimo._ast.cell import CellConfig, CellId_t+from marimo._ast.cell import CellConfigfrom marimo._config.config import MarimoConfigfrom marimo._runtime.requests import (ExecuteMultipleRequest,@@ -13,8 +13,7 @@ from marimo._runtime.requests import (HTTPRequest,RenameRequest,)--UIElementId = str+from marimo._types.ids import CellId_t, UIElementId@dataclassdiff --git a/marimo/_server/session/session_view.py b/marimo/_server/session/session_view.pyindex 42f8bebee3..a6179ece05 100644--- a/marimo/_server/session/session_view.py+++ b/marimo/_server/session/session_view.py@@ -5,7 +5,6 @@ import timefrom dataclasses import dataclassfrom typing import Any, Literal, Optional-from marimo._ast.cell import CellId_tfrom marimo._data.models import DataSourceConnection, DataTablefrom marimo._messaging.cell_output import CellChannel, CellOutputfrom marimo._messaging.ops import (@@ -27,6 +26,7 @@ from marimo._runtime.requests import (ExecutionRequest,SetUIElementValueRequest,)+from marimo._types.ids import CellId_tfrom marimo._utils.lists import as_listfrom marimo._utils.parse_dataclass import parse_rawdiff --git a/marimo/_server/sessions.py b/marimo/_server/sessions.pyindex 337a2aac76..160edaa50f 100644--- a/marimo/_server/sessions.py+++ b/marimo/_server/sessions.py@@ -31,7 +31,7 @@ from typing import Any, Dict, Optional, Unionfrom uuid import uuid4from marimo import _loggers-from marimo._ast.cell import CellConfig, CellId_t+from marimo._ast.cell import CellConfigfrom marimo._cli.print import redfrom marimo._config.manager import MarimoConfigReaderfrom marimo._config.settings import GLOBAL_SETTINGS@@ -59,7 +59,6 @@ from marimo._runtime.requests import (from marimo._server.exceptions import InvalidSessionExceptionfrom marimo._server.file_manager import AppFileManagerfrom marimo._server.file_router import AppFileRouter, MarimoFileKey-from marimo._server.ids import ConsumerId, SessionIdfrom marimo._server.model import ConnectionState, SessionConsumer, SessionModefrom marimo._server.models.models import InstantiateRequestfrom marimo._server.recents import RecentFilesManager@@ -71,6 +70,7 @@ from marimo._server.tokens import AuthToken, SkewProtectionTokenfrom marimo._server.types import QueueTypefrom marimo._server.utils import print_, print_tabbedfrom marimo._tracer import server_tracer+from marimo._types.ids import CellId_t, ConsumerId, SessionIdfrom marimo._utils.disposable import Disposablefrom marimo._utils.distributor import (ConnectionDistributor,diff --git a/marimo/_server/templates/templates.py b/marimo/_server/templates/templates.pyindex ad55165b91..e3d9b7b498 100644--- a/marimo/_server/templates/templates.py+++ b/marimo/_server/templates/templates.py@@ -9,7 +9,7 @@ from typing import Any, List, Literal, Optional, castfrom marimo import __version__from marimo._ast.app import _AppConfig-from marimo._ast.cell import CellConfig, CellId_t+from marimo._ast.cell import CellConfigfrom marimo._config.config import MarimoConfig, PartialMarimoConfigfrom marimo._messaging.cell_output import CellOutputfrom marimo._output.utils import uri_encode_component@@ -17,6 +17,7 @@ from marimo._server.api.utils import parse_titlefrom marimo._server.file_manager import read_css_file, read_html_head_filefrom marimo._server.model import SessionModefrom marimo._server.tokens import SkewProtectionToken+from marimo._types.ids import CellId_tfrom marimo._utils.versions import is_editablediff --git a/marimo/_types/ids.py b/marimo/_types/ids.pynew file mode 100644index 0000000000..8083ceb128--- /dev/null+++ b/marimo/_types/ids.py@@ -0,0 +1,18 @@+from __future__ import annotations++from typing import NewType++# TODO: enable NewType for better type checking+# CellId_t = NewType("CellId_t", str)+CellId_t = str++# UIElementId = NewType("UIElementId", str)+UIElementId = str++# SessionId = NewType("SessionId", str)+SessionId = str++ConsumerId = NewType("ConsumerId", str)++# VariableName = NewType("VariableName", str)+VariableName = strdiff --git a/marimo/_utils/formatter.py b/marimo/_utils/formatter.pyindex dbf87fd7bd..d92fff4b4a 100644--- a/marimo/_utils/formatter.py+++ b/marimo/_utils/formatter.py@@ -7,10 +7,10 @@ from typing import Dictfrom marimo import _loggersfrom marimo._dependencies.dependencies import DependencyManager+from marimo._types.ids import CellId_tLOGGER = _loggers.marimo_logger()-CellId_t = strCellCodes = Dict[CellId_t, str]diff --git a/tests/_server/session/test_session_view.py b/tests/_server/session/test_session_view.pyindex d9d1dc7f4a..da45db17b4 100644--- a/tests/_server/session/test_session_view.py+++ b/tests/_server/session/test_session_view.py@@ -4,7 +4,7 @@ from __future__ import annotationsfrom typing import Anyfrom unittest.mock import patch-from marimo._ast.cell import CellId_t, RuntimeStateType+from marimo._ast.cell import RuntimeStateTypefrom marimo._data.models import DataTable, DataTableColumnfrom marimo._messaging.cell_output import CellChannel, CellOutputfrom marimo._messaging.ops import (@@ -27,6 +27,7 @@ from marimo._runtime.requests import (SetUIElementValueRequest,)from marimo._server.session.session_view import SessionView+from marimo._types.ids import CellId_tfrom marimo._utils.parse_dataclass import parse_rawcell_id: CellId_t = "cell_1"diff --git a/tests/conftest.py b/tests/conftest.pyindex a8f9246fc7..971874c67f 100644--- a/tests/conftest.py+++ b/tests/conftest.py@@ -14,7 +14,6 @@ import pytestfrom _pytest import runnerfrom marimo._ast.app import App, CellManager-from marimo._ast.cell import CellId_tfrom marimo._config.config import DEFAULT_CONFIGfrom marimo._messaging.mimetypes import KnownMimeTypefrom marimo._messaging.ops import CellOp, MessageOperation@@ -34,6 +33,7 @@ from marimo._runtime.marimo_pdb import MarimoPdbfrom marimo._runtime.requests import AppMetadata, ExecutionRequestfrom marimo._runtime.runtime import Kernelfrom marimo._server.model import SessionMode+from marimo._types.ids import CellId_tfrom marimo._utils.parse_dataclass import parse_rawif TYPE_CHECKING: