Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 19 additions & 20 deletions marimo/_ast/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,12 @@
import os
import sys
import threading
from collections.abc import Iterable, Iterator, Mapping
from collections.abc import (
Iterable,
Iterator,
Mapping,
Sequence, # noqa: TC003
)
from dataclasses import dataclass
from pathlib import Path
from textwrap import dedent
Expand All @@ -16,40 +21,28 @@
Callable,
Literal,
Optional,
ParamSpec,
TypeAlias,
TypeVar,
Union,
cast,
overload,
)

from marimo._ast.app_config import _AppConfig
from marimo._ast.cell_id import external_prefix
from marimo._ast.parse import ast_parse
from marimo._ast.variables import BUILTINS
from marimo._convert.converters import MarimoConvert
from marimo._schemas.serialization import (
AppInstantiation,
CellDef,
NotebookSerializationV1,
)
from marimo._types.ids import CellId_t

if sys.version_info < (3, 10):
from typing_extensions import ParamSpec, TypeAlias
else:
from typing import ParamSpec, TypeAlias

from collections.abc import Sequence # noqa: TC003

from marimo import _loggers
from marimo._ast.app_config import _AppConfig
from marimo._ast.cell import Cell, CellConfig, CellImpl
from marimo._ast.cell_id import external_prefix
from marimo._ast.cell_manager import CellManager
from marimo._ast.errors import (
CycleError,
MultipleDefinitionError,
SetupRootError,
UnparsableError,
)
from marimo._ast.parse import ast_parse
from marimo._ast.variables import BUILTINS
from marimo._convert.converters import MarimoConvert
from marimo._messaging.mimetypes import KnownMimeType
from marimo._output.hypertext import Html
from marimo._output.rich_help import mddoc
Expand All @@ -65,6 +58,12 @@
FunctionCallRequest,
SetUIElementValueRequest,
)
from marimo._schemas.serialization import (
AppInstantiation,
CellDef,
NotebookSerializationV1,
)
from marimo._types.ids import CellId_t

if TYPE_CHECKING:
from collections.abc import Sequence
Expand Down
10 changes: 3 additions & 7 deletions marimo/_ast/cell_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,15 @@
from __future__ import annotations

import os
import sys
from typing import (
TYPE_CHECKING,
Callable,
Optional,
ParamSpec,
TypeAlias,
TypeVar,
)

if sys.version_info < (3, 10):
from typing_extensions import ParamSpec, TypeAlias
else:
from typing import ParamSpec, TypeAlias

from marimo import _loggers
from marimo._ast.cell import Cell, CellConfig
from marimo._ast.cell_id import CellIdGenerator
Expand Down Expand Up @@ -44,7 +40,7 @@
R = TypeVar("R")
Fn: TypeAlias = Callable[P, R]
Cls: TypeAlias = type
Obj: TypeAlias = "Cls | Fn[P, R]"
Obj: TypeAlias = Cls | Fn[P, R]

LOGGER = _loggers.marimo_logger()

Expand Down
5 changes: 1 addition & 4 deletions marimo/_ast/codegen.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,7 @@
if TYPE_CHECKING:
from pathlib import Path

if sys.version_info < (3, 10):
from typing_extensions import TypeAlias
else:
from typing import TypeAlias
from typing import TypeAlias

Cls: TypeAlias = type

Expand Down
8 changes: 1 addition & 7 deletions marimo/_ast/compiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,12 @@
import linecache
import os
import re
import sys
import textwrap
import token as token_types
import warnings
from tokenize import tokenize
from types import CodeType, FrameType
from typing import Any, Callable, Optional, cast
from typing import Any, Callable, Optional, TypeAlias, cast

from marimo import _loggers
from marimo._ast import parse
Expand All @@ -32,11 +31,6 @@
from marimo._types.ids import CellId_t
from marimo._utils.tmpdir import get_tmpdir

if sys.version_info < (3, 10):
from typing_extensions import TypeAlias
else:
from typing import TypeAlias

LOGGER = _loggers.marimo_logger()
Cls: TypeAlias = type

Expand Down
85 changes: 41 additions & 44 deletions marimo/_ast/visitor.py
Original file line number Diff line number Diff line change
Expand Up @@ -1056,52 +1056,49 @@ def visit_ImportFrom(self, node: ast.ImportFrom) -> ast.ImportFrom:
)
return node

if sys.version_info >= (3, 10):
# Match statements were introduced in Python 3.10
#
# Top-level match statements are awkward in marimo --- at parse-time,
# we have to register all names in every case/pattern as globals (since
# we don't know the value of the match subject), even though only a
# subset of the names will be bound at runtime. For this reason, in
# marimo, match statements should really only be used in local scopes.
def visit_MatchAs(self, node: ast.MatchAs) -> ast.MatchAs:
if node.name is not None:
node.name = self._if_local_then_mangle(node.name)
self._define(
node,
node.name,
VariableData(kind="variable"),
)
if node.pattern is not None:
# pattern may contain additional MatchAs statements in it
self.visit(node.pattern)
return node
# Match statements were introduced in Python 3.10
#
# Top-level match statements are awkward in marimo --- at parse-time,
# we have to register all names in every case/pattern as globals (since
# we don't know the value of the match subject), even though only a
# subset of the names will be bound at runtime. For this reason, in
# marimo, match statements should really only be used in local scopes.
def visit_MatchAs(self, node: ast.MatchAs) -> ast.MatchAs:
if node.name is not None:
node.name = self._if_local_then_mangle(node.name)
self._define(
node,
node.name,
VariableData(kind="variable"),
)
if node.pattern is not None:
# pattern may contain additional MatchAs statements in it
self.visit(node.pattern)
return node

def visit_MatchMapping(
self, node: ast.MatchMapping
) -> ast.MatchMapping:
if node.rest is not None:
node.rest = self._if_local_then_mangle(node.rest)
self._define(
node,
node.rest,
VariableData(kind="variable"),
)
for key in node.keys:
self.visit(key)
for pattern in node.patterns:
self.visit(pattern)
return node
def visit_MatchMapping(self, node: ast.MatchMapping) -> ast.MatchMapping:
if node.rest is not None:
node.rest = self._if_local_then_mangle(node.rest)
self._define(
node,
node.rest,
VariableData(kind="variable"),
)
for key in node.keys:
self.visit(key)
for pattern in node.patterns:
self.visit(pattern)
return node

def visit_MatchStar(self, node: ast.MatchStar) -> ast.MatchStar:
if node.name is not None:
node.name = self._if_local_then_mangle(node.name)
self._define(
node,
node.name,
VariableData(kind="variable"),
)
return node
def visit_MatchStar(self, node: ast.MatchStar) -> ast.MatchStar:
if node.name is not None:
node.name = self._if_local_then_mangle(node.name)
self._define(
node,
node.name,
VariableData(kind="variable"),
)
return node

if sys.version_info >= (3, 12):

Expand Down
7 changes: 0 additions & 7 deletions marimo/_cli/development/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -452,13 +452,6 @@ def inline_packages(name: Path) -> None:
if not name.exists():
raise click.FileError(str(name))

# Validate >=3.10 for sys.stdlib_module_names
if sys.version_info < (3, 10):
# TOD: add support for < 3.10
# We can use https://github.com/omnilib/stdlibs
# to get the stdlib module names
raise click.UsageError("Requires Python >=3.10")

package_names = module_name_to_pypi_name()

def get_pypi_package_names() -> list[str]:
Expand Down
22 changes: 11 additions & 11 deletions marimo/_convert/ipynb.py
Original file line number Diff line number Diff line change
Expand Up @@ -404,17 +404,17 @@ def rename_named_node(
name = node.name
new_name = self._maybe_rename(cell, name, is_reference)
node.name = new_name
if sys.version_info >= (3, 10):
if isinstance(node, (ast.MatchAs, ast.MatchStar)):
name = node.name
if name is not None:
new_name = self._maybe_rename(cell, name, is_reference)
node.name = new_name
elif isinstance(node, ast.MatchMapping):
name = node.rest
if name is not None:
new_name = self._maybe_rename(cell, name, is_reference)
node.rest = new_name

if isinstance(node, (ast.MatchAs, ast.MatchStar)):
name = node.name
if name is not None:
new_name = self._maybe_rename(cell, name, is_reference)
node.name = new_name
elif isinstance(node, ast.MatchMapping):
name = node.rest
if name is not None:
new_name = self._maybe_rename(cell, name, is_reference)
node.rest = new_name
if sys.version_info >= (3, 12):
if isinstance(
node, (ast.TypeVar, ast.ParamSpec, ast.TypeVarTuple)
Expand Down
10 changes: 5 additions & 5 deletions marimo/_messaging/ops.py
Original file line number Diff line number Diff line change
Expand Up @@ -613,14 +613,14 @@ class ColumnPreview(msgspec.Struct):
stats: Optional[ColumnStats] = None


# We shouldn't need to make table_name and column_name have default values.
# We can use kw_only=True once we drop support for Python 3.9 (25-11-01).
class DataColumnPreview(Op, ColumnPreview, tag="data-column-preview"):
class DataColumnPreview(
Op, ColumnPreview, kw_only=True, tag="data-column-preview"
):
"""Preview of a column in a dataset."""

name: ClassVar[str] = "data-column-preview"
table_name: str = ""
column_name: str = ""
table_name: str
column_name: str


class DataSourceConnections(Op, tag="data-source-connections"):
Expand Down
9 changes: 1 addition & 8 deletions marimo/_plugins/core/web_component.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,8 @@
from marimo._output.mime import MIME

if TYPE_CHECKING:
import sys
from collections.abc import Mapping, Sequence

if sys.version_info < (3, 10):
from typing_extensions import TypeAlias
else:
from typing import TypeAlias

from typing import Optional
from typing import Optional, TypeAlias

JSONType: TypeAlias = Union[
Mapping[str, "JSONType"],
Expand Down
14 changes: 3 additions & 11 deletions marimo/_plugins/ui/_core/registry.py
Original file line number Diff line number Diff line change
@@ -1,29 +1,21 @@
# Copyright 2024 Marimo. All rights reserved.
from __future__ import annotations

import sys
import weakref
from typing import TYPE_CHECKING, Any, Optional, TypeVar, Union

from marimo._runtime.context.types import ContextNotInitializedError

if sys.version_info < (3, 10):
from typing_extensions import TypeAlias
else:
from typing import TypeAlias
from typing import TYPE_CHECKING, Any, Optional, TypeAlias, TypeVar

from marimo._ast.app import _Namespace
from marimo._plugins.ui._core.ui_element import UIElement
from marimo._runtime.context import get_context
from marimo._runtime.context.types import ContextNotInitializedError
from marimo._types.ids import CellId_t, UIElementId

if TYPE_CHECKING:
from collections.abc import Iterable, Mapping

T = TypeVar("T")

# Recursive types don't support | or dict[] in py3.8/3.9 (25-11-01)
LensValue: TypeAlias = Union[T, dict[str, "LensValue[T]"]]
LensValue: TypeAlias = T | dict[str, "LensValue[T]"]


class UIElementRegistry:
Expand Down
6 changes: 1 addition & 5 deletions marimo/_plugins/ui/_impl/altair_chart.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
Final,
Literal,
Optional,
TypeAlias,
Union,
cast,
)
Expand All @@ -33,11 +34,6 @@
is_narwhals_lazyframe,
)

if sys.version_info < (3, 10):
from typing_extensions import TypeAlias
else:
from typing import TypeAlias

LOGGER = _loggers.marimo_logger()

if TYPE_CHECKING:
Expand Down
7 changes: 1 addition & 6 deletions marimo/_server/asgi.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,7 @@
)

if TYPE_CHECKING:
import sys

if sys.version_info < (3, 10):
from typing_extensions import TypeAlias
else:
from typing import TypeAlias
from typing import TypeAlias

from starlette.requests import Request
from starlette.responses import Response
Expand Down
Loading
Loading