diff --git a/crates/re_types_builder/src/codegen/python/mod.rs b/crates/re_types_builder/src/codegen/python/mod.rs index f81bc6e6c85f..5582aa83d8ec 100644 --- a/crates/re_types_builder/src/codegen/python/mod.rs +++ b/crates/re_types_builder/src/codegen/python/mod.rs @@ -847,7 +847,12 @@ fn code_for_enum( } } - code.push_unindented(format!("{name}Like = Union[{name}, str]"), 1); + let variants = obj + .fields + .iter() + .map(|v| format!("Literal[{:?}]", v.snake_case_name())) + .join(" | "); + code.push_unindented(format!("{name}Like = Union[{name}, {variants}]"), 1); code.push_unindented( format!( r#" diff --git a/rerun_py/rerun_sdk/rerun/blueprint/__init__.py b/rerun_py/rerun_sdk/rerun/blueprint/__init__.py index edeecdb62dd0..a325c83ee7a2 100644 --- a/rerun_py/rerun_sdk/rerun/blueprint/__init__.py +++ b/rerun_py/rerun_sdk/rerun/blueprint/__init__.py @@ -13,6 +13,8 @@ BlueprintPart, Container, ContainerLike, + PanelState, + PanelStateLike, SelectionPanel, SpaceView, TimePanel, diff --git a/rerun_py/rerun_sdk/rerun/blueprint/components/background_kind.py b/rerun_py/rerun_sdk/rerun/blueprint/components/background_kind.py index cdc8fc4eef9b..0376eca2bd29 100644 --- a/rerun_py/rerun_sdk/rerun/blueprint/components/background_kind.py +++ b/rerun_py/rerun_sdk/rerun/blueprint/components/background_kind.py @@ -5,7 +5,7 @@ from __future__ import annotations -from typing import Sequence, Union +from typing import Literal, Sequence, Union import pyarrow as pa @@ -44,7 +44,9 @@ class BackgroundKind(Enum): """Simple uniform color.""" -BackgroundKindLike = Union[BackgroundKind, str] +BackgroundKindLike = Union[ + BackgroundKind, Literal["gradient_dark"] | Literal["gradient_bright"] | Literal["solid_color"] +] BackgroundKindArrayLike = Union[BackgroundKindLike, Sequence[BackgroundKindLike]] diff --git a/rerun_py/rerun_sdk/rerun/blueprint/components/container_kind.py b/rerun_py/rerun_sdk/rerun/blueprint/components/container_kind.py index e0347d25a5df..4c766ca14458 100644 --- a/rerun_py/rerun_sdk/rerun/blueprint/components/container_kind.py +++ b/rerun_py/rerun_sdk/rerun/blueprint/components/container_kind.py @@ -5,7 +5,7 @@ from __future__ import annotations -from typing import Sequence, Union +from typing import Literal, Sequence, Union import pyarrow as pa @@ -26,7 +26,9 @@ class ContainerKind(Enum): Grid = 4 -ContainerKindLike = Union[ContainerKind, str] +ContainerKindLike = Union[ + ContainerKind, Literal["tabs"] | Literal["horizontal"] | Literal["vertical"] | Literal["grid"] +] ContainerKindArrayLike = Union[ContainerKindLike, Sequence[ContainerKindLike]] diff --git a/rerun_py/rerun_sdk/rerun/blueprint/components/corner2d.py b/rerun_py/rerun_sdk/rerun/blueprint/components/corner2d.py index a316f43cc4c7..bf37df09ab67 100644 --- a/rerun_py/rerun_sdk/rerun/blueprint/components/corner2d.py +++ b/rerun_py/rerun_sdk/rerun/blueprint/components/corner2d.py @@ -5,7 +5,7 @@ from __future__ import annotations -from typing import Sequence, Union +from typing import Literal, Sequence, Union import pyarrow as pa @@ -33,7 +33,9 @@ class Corner2D(Enum): """Right bottom corner.""" -Corner2DLike = Union[Corner2D, str] +Corner2DLike = Union[ + Corner2D, Literal["left_top"] | Literal["right_top"] | Literal["left_bottom"] | Literal["right_bottom"] +] Corner2DArrayLike = Union[Corner2DLike, Sequence[Corner2DLike]] diff --git a/rerun_py/rerun_sdk/rerun/blueprint/components/panel_state.py b/rerun_py/rerun_sdk/rerun/blueprint/components/panel_state.py index 69445a8fb683..d3a62e31b1c1 100644 --- a/rerun_py/rerun_sdk/rerun/blueprint/components/panel_state.py +++ b/rerun_py/rerun_sdk/rerun/blueprint/components/panel_state.py @@ -5,7 +5,7 @@ from __future__ import annotations -from typing import Sequence, Union +from typing import Literal, Sequence, Union import pyarrow as pa @@ -30,7 +30,7 @@ class PanelState(Enum): """Fully expanded.""" -PanelStateLike = Union[PanelState, str] +PanelStateLike = Union[PanelState, Literal["hidden"] | Literal["collapsed"] | Literal["expanded"]] PanelStateArrayLike = Union[PanelStateLike, Sequence[PanelStateLike]] diff --git a/rerun_py/rerun_sdk/rerun/components/marker_shape.py b/rerun_py/rerun_sdk/rerun/components/marker_shape.py index 108c5748e985..06548c8cfd49 100644 --- a/rerun_py/rerun_sdk/rerun/components/marker_shape.py +++ b/rerun_py/rerun_sdk/rerun/components/marker_shape.py @@ -5,7 +5,7 @@ from __future__ import annotations -from typing import Sequence, Union +from typing import Literal, Sequence, Union import pyarrow as pa @@ -51,7 +51,19 @@ class MarkerShape(Enum): """`*`""" -MarkerShapeLike = Union[MarkerShape, str] +MarkerShapeLike = Union[ + MarkerShape, + Literal["circle"] + | Literal["diamond"] + | Literal["square"] + | Literal["cross"] + | Literal["plus"] + | Literal["up"] + | Literal["down"] + | Literal["left"] + | Literal["right"] + | Literal["asterisk"], +] MarkerShapeArrayLike = Union[MarkerShapeLike, Sequence[MarkerShapeLike]] diff --git a/rerun_py/tests/test_types/components/enum_test.py b/rerun_py/tests/test_types/components/enum_test.py index c57d80a06268..c3c89f3ba8a6 100644 --- a/rerun_py/tests/test_types/components/enum_test.py +++ b/rerun_py/tests/test_types/components/enum_test.py @@ -5,7 +5,7 @@ from __future__ import annotations -from typing import Sequence, Union +from typing import Literal, Sequence, Union import pyarrow as pa from rerun._baseclasses import BaseBatch, BaseExtensionType, ComponentBatchMixin @@ -38,7 +38,10 @@ class EnumTest(Enum): """Baby's got it.""" -EnumTestLike = Union[EnumTest, str] +EnumTestLike = Union[ + EnumTest, + Literal["up"] | Literal["down"] | Literal["right"] | Literal["left"] | Literal["forward"] | Literal["back"], +] EnumTestArrayLike = Union[EnumTestLike, Sequence[EnumTestLike]]