Skip to content

Commit 3e7dc6e

Browse files
committed
fix(schema): Replace union types with Optional for better type clarity in Pydantic models
1 parent 1837301 commit 3e7dc6e

File tree

1 file changed

+29
-29
lines changed

1 file changed

+29
-29
lines changed

datalab/webapi/schema.py

Lines changed: 29 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
from __future__ import annotations
2626

2727
from enum import Enum
28-
from typing import Any
28+
from typing import Any, Optional
2929

3030
from pydantic import BaseModel, Field
3131

@@ -50,13 +50,13 @@ class ObjectMetadata(BaseModel):
5050
dtype: str = Field(..., description="NumPy dtype string (e.g., 'float64')")
5151

5252
# Optional metadata
53-
title: str | None = Field(None, description="Display title")
54-
xlabel: str | None = Field(None, description="X-axis label")
55-
ylabel: str | None = Field(None, description="Y-axis label")
56-
zlabel: str | None = Field(None, description="Z-axis label (images only)")
57-
xunit: str | None = Field(None, description="X-axis unit")
58-
yunit: str | None = Field(None, description="Y-axis unit")
59-
zunit: str | None = Field(None, description="Z-axis unit (images only)")
53+
title: Optional[str] = Field(None, description="Display title")
54+
xlabel: Optional[str] = Field(None, description="X-axis label")
55+
ylabel: Optional[str] = Field(None, description="Y-axis label")
56+
zlabel: Optional[str] = Field(None, description="Z-axis label (images only)")
57+
xunit: Optional[str] = Field(None, description="X-axis unit")
58+
yunit: Optional[str] = Field(None, description="Y-axis unit")
59+
zunit: Optional[str] = Field(None, description="Z-axis unit (images only)")
6060

6161
# Extended attributes
6262
attributes: dict[str, Any] = Field(
@@ -81,13 +81,13 @@ class ObjectCreateRequest(BaseModel):
8181
overwrite: bool = Field(False, description="Replace existing object if present")
8282

8383
# Optional metadata to set
84-
title: str | None = Field(None, description="Display title")
85-
xlabel: str | None = Field(None, description="X-axis label")
86-
ylabel: str | None = Field(None, description="Y-axis label")
87-
zlabel: str | None = Field(None, description="Z-axis label (images only)")
88-
xunit: str | None = Field(None, description="X-axis unit")
89-
yunit: str | None = Field(None, description="Y-axis unit")
90-
zunit: str | None = Field(None, description="Z-axis unit (images only)")
84+
title: Optional[str] = Field(None, description="Display title")
85+
xlabel: Optional[str] = Field(None, description="X-axis label")
86+
ylabel: Optional[str] = Field(None, description="Y-axis label")
87+
zlabel: Optional[str] = Field(None, description="Z-axis label (images only)")
88+
xunit: Optional[str] = Field(None, description="X-axis unit")
89+
yunit: Optional[str] = Field(None, description="Y-axis unit")
90+
zunit: Optional[str] = Field(None, description="Z-axis unit (images only)")
9191
attributes: dict[str, Any] = Field(
9292
default_factory=dict, description="Additional metadata"
9393
)
@@ -96,14 +96,14 @@ class ObjectCreateRequest(BaseModel):
9696
class MetadataPatchRequest(BaseModel):
9797
"""Request to update object metadata."""
9898

99-
title: str | None = Field(None, description="New display title")
100-
xlabel: str | None = Field(None, description="New X-axis label")
101-
ylabel: str | None = Field(None, description="New Y-axis label")
102-
zlabel: str | None = Field(None, description="New Z-axis label")
103-
xunit: str | None = Field(None, description="New X-axis unit")
104-
yunit: str | None = Field(None, description="New Y-axis unit")
105-
zunit: str | None = Field(None, description="New Z-axis unit")
106-
attributes: dict[str, Any] | None = Field(
99+
title: Optional[str] = Field(None, description="New display title")
100+
xlabel: Optional[str] = Field(None, description="New X-axis label")
101+
ylabel: Optional[str] = Field(None, description="New Y-axis label")
102+
zlabel: Optional[str] = Field(None, description="New Z-axis label")
103+
xunit: Optional[str] = Field(None, description="New X-axis unit")
104+
yunit: Optional[str] = Field(None, description="New Y-axis unit")
105+
zunit: Optional[str] = Field(None, description="New Z-axis unit")
106+
attributes: Optional[dict[str, Any]] = Field(
107107
None, description="Attributes to merge (not replace)"
108108
)
109109

@@ -114,7 +114,7 @@ class ApiStatus(BaseModel):
114114
running: bool = Field(..., description="Whether the API server is running")
115115
version: str = Field(..., description="DataLab version")
116116
api_version: str = Field("v1", description="API version")
117-
url: str | None = Field(None, description="Base URL when running")
117+
url: Optional[str] = Field(None, description="Base URL when running")
118118
workspace_mode: str = Field(..., description="Current workspace mode")
119119
localhost_no_token: bool = Field(
120120
False, description="Whether localhost connections can bypass authentication"
@@ -126,7 +126,7 @@ class ErrorResponse(BaseModel):
126126

127127
error: str = Field(..., description="Error type/code")
128128
message: str = Field(..., description="Human-readable error message")
129-
detail: str | None = Field(None, description="Additional detail")
129+
detail: Optional[str] = Field(None, description="Additional detail")
130130

131131

132132
# Event types for WebSocket (future)
@@ -144,8 +144,8 @@ class WorkspaceEvent(BaseModel):
144144
"""A workspace change event (for WebSocket notifications)."""
145145

146146
event: EventType = Field(..., description="Event type")
147-
object_name: str | None = Field(None, description="Affected object name")
148-
old_name: str | None = Field(None, description="Old name (for rename events)")
147+
object_name: Optional[str] = Field(None, description="Affected object name")
148+
old_name: Optional[str] = Field(None, description="Old name (for rename events)")
149149
timestamp: float = Field(..., description="Unix timestamp")
150150

151151

@@ -160,7 +160,7 @@ class SelectObjectsRequest(BaseModel):
160160
selection: list[str] = Field(
161161
..., description="List of object names/titles to select"
162162
)
163-
panel: ObjectType | None = Field(
163+
panel: Optional[ObjectType] = Field(
164164
None, description="Panel to select in (signal/image). None = current panel."
165165
)
166166

@@ -181,7 +181,7 @@ class CalcRequest(BaseModel):
181181
name: str = Field(
182182
..., description="Computation function name (e.g., 'normalize', 'fft')"
183183
)
184-
param: dict[str, Any] | None = Field(
184+
param: Optional[dict[str, Any]] = Field(
185185
None,
186186
description="Computation parameters as a dictionary. "
187187
"Keys are parameter names, values are parameter values.",

0 commit comments

Comments
 (0)