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
fix(schema): cover generation and preserve brands on Python 3.10 (#11320)
Shahmir Varqha59806299b020
diff --git a/marimo/_cli/development/schema.py b/marimo/_cli/development/schema.pyindex b2ddc14ebe..98cf952272 100644--- a/marimo/_cli/development/schema.py+++ b/marimo/_cli/development/schema.py@@ -142,9 +142,7 @@ def _enrich_branded_types(passdef _visit_annotation(ty: Any) -> None:- if isinstance(ty, type):- _visit_type(ty)- return+ _visit_type(ty)for arg in typing.get_args(ty):if arg is not Ellipsis and arg is not type(None):_visit_annotation(arg)diff --git a/tests/_cli/test_cli_development.py b/tests/_cli/test_cli_development.pyindex c2b7a26845..3794e669ef 100644--- a/tests/_cli/test_cli_development.py+++ b/tests/_cli/test_cli_development.py@@ -3,68 +3,10 @@ from __future__ import annotationsimport jsonimport subprocess-from typing import Any, get_args+from typing import Anyimport yaml-from marimo._cli.development.schema import generate_server_api_schema-from marimo._runtime import commands---def test_openapi_exports_only_client_commands() -> None:- schemas = generate_server_api_schema()["components"]["schemas"]- command_names = {- model.__name__- for model in vars(commands).values()- if isinstance(model, type) and issubclass(model, commands.Command)- }-- assert command_names & schemas.keys() == {- command.__name__ for command in get_args(commands.ClientCommand)- }---def test_openapi_preserves_brands_in_client_commands() -> None:- schemas = generate_server_api_schema()["components"]["schemas"]-- assert schemas["ExecuteCellsCommand"]["properties"]["cellIds"] == {- "type": "array",- "items": {"$ref": "#/components/schemas/CellId"},- }- assert schemas["UpdateUIElementCommand"]["properties"]["objectIds"] == {- "type": "array",- "items": {"$ref": "#/components/schemas/UIElementId"},- }---def test_openapi_known_unions_reference_named_exports() -> None:- schemas = generate_server_api_schema()["components"]["schemas"]-- assert {- "NotificationMessage",- "ClientCommand",- "MarimoError",- "DataType",- } <= schemas.keys()- assert schemas["KnownUnions"] == {- "title": "KnownUnions",- "deprecated": True,- "description": (- "Use the named NotificationMessage, ClientCommand, MarimoError, "- "and DataType schemas directly."- ),- "type": "object",- "properties": {- "notification": {- "$ref": "#/components/schemas/NotificationMessage"- },- "command": {"$ref": "#/components/schemas/ClientCommand"},- "error": {"$ref": "#/components/schemas/MarimoError"},- "data_type": {"$ref": "#/components/schemas/DataType"},- },- "required": ["notification", "command", "error", "data_type"],- }-def _normalize_union_order(schema: Any) -> Any:if isinstance(schema, list):diff --git a/tests/_cli/test_cli_schema.py b/tests/_cli/test_openapi_schema.pysimilarity index 54%rename from tests/_cli/test_cli_schema.pyrename to tests/_cli/test_openapi_schema.pyindex 15b280239e..811aa690b4 100644--- a/tests/_cli/test_cli_schema.py+++ b/tests/_cli/test_openapi_schema.py@@ -1,12 +1,16 @@# Copyright 2026 Marimo. All rights reserved.from __future__ import annotations-from typing import Literal+from typing import Literal, get_argsimport msgspecimport pytest-from marimo._cli.development.schema import _generate_schema_components+from marimo._cli.development.schema import (+ _generate_schema_components,+ generate_server_api_schema,+)+from marimo._runtime import commandsfrom marimo._types.ids import CellId_t@@ -83,3 +87,58 @@ def test_exporting_a_struct_under_its_own_name() -> None:def test_export_name_cannot_overwrite_a_dependency(name: str) -> None:with pytest.raises(ValueError, match=f"Schema export '{name}' conflicts"):_generate_schema_components([Payload], {name: Literal["other"]})+++def test_openapi_exports_only_client_commands() -> None:+ schemas = generate_server_api_schema()["components"]["schemas"]+ command_names = {+ model.__name__+ for model in vars(commands).values()+ if isinstance(model, type) and issubclass(model, commands.Command)+ }++ assert command_names & schemas.keys() == {+ command.__name__ for command in get_args(commands.ClientCommand)+ }+++def test_openapi_preserves_brands_in_client_commands() -> None:+ schemas = generate_server_api_schema()["components"]["schemas"]++ assert schemas["ExecuteCellsCommand"]["properties"]["cellIds"] == {+ "type": "array",+ "items": {"$ref": "#/components/schemas/CellId"},+ }+ assert schemas["UpdateUIElementCommand"]["properties"]["objectIds"] == {+ "type": "array",+ "items": {"$ref": "#/components/schemas/UIElementId"},+ }+++def test_openapi_known_unions_reference_named_exports() -> None:+ schemas = generate_server_api_schema()["components"]["schemas"]++ assert {+ "NotificationMessage",+ "ClientCommand",+ "MarimoError",+ "DataType",+ } <= schemas.keys()+ assert schemas["KnownUnions"] == {+ "title": "KnownUnions",+ "deprecated": True,+ "description": (+ "Use the named NotificationMessage, ClientCommand, MarimoError, "+ "and DataType schemas directly."+ ),+ "type": "object",+ "properties": {+ "notification": {+ "$ref": "#/components/schemas/NotificationMessage"+ },+ "command": {"$ref": "#/components/schemas/ClientCommand"},+ "error": {"$ref": "#/components/schemas/MarimoError"},+ "data_type": {"$ref": "#/components/schemas/DataType"},+ },+ "required": ["notification", "command", "error", "data_type"],+ }