Skip to content

Commit 600e52d

Browse files
committed
fix: remove typing optional
1 parent f7ea61b commit 600e52d

File tree

16 files changed

+103
-107
lines changed

16 files changed

+103
-107
lines changed

src/uipath/runtime/base.py

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
Any,
66
AsyncGenerator,
77
Literal,
8-
Optional,
98
Protocol,
109
)
1110

@@ -38,7 +37,7 @@ class UiPathExecuteOptions(BaseModel):
3837
default=False,
3938
description="Indicates whether to resume a suspended execution.",
4039
)
41-
breakpoints: Optional[list[str] | Literal["*"]] = Field(
40+
breakpoints: list[str] | Literal["*"] | None = Field(
4241
default=None,
4342
description="List of nodes or '*' to break on all steps.",
4443
)
@@ -57,8 +56,8 @@ class UiPathExecutableProtocol(Protocol):
5756

5857
async def execute(
5958
self,
60-
input: Optional[dict[str, Any]] = None,
61-
options: Optional[UiPathExecuteOptions] = None,
59+
input: dict[str, Any] | None = None,
60+
options: UiPathExecuteOptions | None = None,
6261
) -> UiPathRuntimeResult:
6362
"""Execute the runtime with the given input and options."""
6463
...
@@ -69,8 +68,8 @@ class UiPathStreamableProtocol(Protocol):
6968

7069
async def stream(
7170
self,
72-
input: Optional[dict[str, Any]] = None,
73-
options: Optional[UiPathStreamOptions] = None,
71+
input: dict[str, Any] | None = None,
72+
options: UiPathStreamOptions | None = None,
7473
) -> AsyncGenerator[UiPathRuntimeEvent, None]:
7574
"""Stream execution events in real-time.
7675
@@ -147,9 +146,9 @@ def __init__(
147146
delegate: UiPathRuntimeProtocol,
148147
trace_manager: UiPathTraceManager,
149148
root_span: str = "root",
150-
span_attributes: Optional[dict[str, str]] = None,
151-
log_handler: Optional[UiPathRuntimeExecutionLogHandler] = None,
152-
execution_id: Optional[str] = None,
149+
span_attributes: dict[str, str] | None = None,
150+
log_handler: UiPathRuntimeExecutionLogHandler | None = None,
151+
execution_id: str | None = None,
153152
):
154153
"""Initialize the executor."""
155154
self.delegate = delegate
@@ -163,8 +162,8 @@ def __init__(
163162

164163
async def execute(
165164
self,
166-
input: Optional[dict[str, Any]] = None,
167-
options: Optional[UiPathExecuteOptions] = None,
165+
input: dict[str, Any] | None = None,
166+
options: UiPathExecuteOptions | None = None,
168167
) -> UiPathRuntimeResult:
169168
"""Execute runtime with context."""
170169
if self.log_handler:
@@ -190,8 +189,8 @@ async def execute(
190189

191190
async def stream(
192191
self,
193-
input: Optional[dict[str, Any]] = None,
194-
options: Optional[UiPathStreamOptions] = None,
192+
input: dict[str, Any] | None = None,
193+
options: UiPathStreamOptions | None = None,
195194
) -> AsyncGenerator[UiPathRuntimeEvent, None]:
196195
"""Stream runtime execution with context.
197196

src/uipath/runtime/context.py

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,10 @@
66
from functools import cached_property
77
from typing import (
88
Any,
9-
Optional,
109
TypeVar,
1110
)
1211

13-
from pydantic import BaseModel
12+
from pydantic import BaseModel, ConfigDict
1413

1514
from uipath.runtime.errors import (
1615
UiPathErrorCategory,
@@ -29,21 +28,21 @@
2928
class UiPathRuntimeContext(BaseModel):
3029
"""Context information passed throughout the runtime execution."""
3130

32-
entrypoint: Optional[str] = None
33-
input: Optional[dict[str, Any]] = None
34-
job_id: Optional[str] = None
31+
entrypoint: str | None = None
32+
input: dict[str, Any] | None = None
33+
job_id: str | None = None
3534
config_path: str = "uipath.json"
36-
runtime_dir: Optional[str] = "__uipath"
35+
runtime_dir: str | None = "__uipath"
3736
result_file: str = "output.json"
3837
state_file: str = "state.db"
39-
input_file: Optional[str] = None
40-
output_file: Optional[str] = None
41-
trace_file: Optional[str] = None
42-
logs_file: Optional[str] = "execution.log"
43-
logs_min_level: Optional[str] = "INFO"
44-
result: Optional[UiPathRuntimeResult] = None
38+
input_file: str | None = None
39+
output_file: str | None = None
40+
trace_file: str | None = None
41+
logs_file: str | None = "execution.log"
42+
logs_min_level: str | None = "INFO"
43+
result: UiPathRuntimeResult | None = None
4544

46-
model_config = {"arbitrary_types_allowed": True, "extra": "allow"}
45+
model_config = ConfigDict(arbitrary_types_allowed=True, extra="allow")
4746

4847
def __enter__(self):
4948
"""Async enter method called when entering the 'async with' block.
@@ -188,7 +187,7 @@ def state_file_path(self) -> str:
188187
return os.path.join("__uipath", "state.db")
189188

190189
@classmethod
191-
def with_defaults(cls: type[C], config_path: Optional[str] = None, **kwargs) -> C:
190+
def with_defaults(cls: type[C], config_path: str | None = None, **kwargs) -> C:
192191
"""Construct a context with defaults, reading env vars and config file."""
193192
resolved_config_path = config_path or os.environ.get(
194193
"UIPATH_CONFIG_PATH", "uipath.json"
@@ -212,7 +211,7 @@ def with_defaults(cls: type[C], config_path: Optional[str] = None, **kwargs) ->
212211
return base
213212

214213
@classmethod
215-
def from_config(cls: type[C], config_path: Optional[str] = None, **kwargs) -> C:
214+
def from_config(cls: type[C], config_path: str | None = None, **kwargs) -> C:
216215
"""Load configuration from uipath.json file."""
217216
path = config_path or "uipath.json"
218217
config = {}

src/uipath/runtime/debug/runtime.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
import asyncio
44
import logging
5-
from typing import Any, AsyncGenerator, Optional, cast
5+
from typing import Any, AsyncGenerator, cast
66

77
from uipath.runtime.base import (
88
UiPathExecuteOptions,
@@ -56,8 +56,8 @@ def __init__(
5656

5757
async def execute(
5858
self,
59-
input: Optional[dict[str, Any]] = None,
60-
options: Optional[UiPathExecuteOptions] = None,
59+
input: dict[str, Any] | None = None,
60+
options: UiPathExecuteOptions | None = None,
6161
) -> UiPathRuntimeResult:
6262
"""Execute the workflow with debug support."""
6363
final_result = None
@@ -73,15 +73,15 @@ async def execute(
7373

7474
async def stream(
7575
self,
76-
input: Optional[dict[str, Any]] = None,
77-
options: Optional[UiPathStreamOptions] = None,
76+
input: dict[str, Any] | None = None,
77+
options: UiPathStreamOptions | None = None,
7878
) -> AsyncGenerator[UiPathRuntimeEvent, None]:
7979
"""Stream execution events with debug support."""
8080
try:
8181
await self.debug_bridge.connect()
8282
await self.debug_bridge.emit_execution_started()
8383

84-
result: Optional[UiPathRuntimeResult] = None
84+
result: UiPathRuntimeResult | None = None
8585

8686
# Try to stream events from inner runtime
8787
try:
@@ -107,8 +107,8 @@ async def stream(
107107

108108
async def _stream_and_debug(
109109
self,
110-
input: Optional[dict[str, Any]] = None,
111-
options: Optional[UiPathExecuteOptions] = None,
110+
input: dict[str, Any] | None = None,
111+
options: UiPathExecuteOptions | None = None,
112112
) -> AsyncGenerator[UiPathRuntimeEvent, None]:
113113
"""Stream events from inner runtime and handle debug interactions."""
114114
final_result: UiPathRuntimeResult
@@ -185,7 +185,7 @@ async def _stream_and_debug(
185185
)
186186
await self.debug_bridge.emit_state_update(state_event)
187187

188-
resume_data: Optional[dict[str, Any]] = None
188+
resume_data: dict[str, Any] | None = None
189189
try:
190190
resume_data = await self._poll_trigger(
191191
final_result.trigger, self.delegate.trigger_manager
@@ -234,7 +234,7 @@ async def dispose(self) -> None:
234234

235235
async def _poll_trigger(
236236
self, trigger: UiPathResumeTrigger, reader: UiPathResumeTriggerReaderProtocol
237-
) -> Optional[dict[str, Any]]:
237+
) -> dict[str, Any] | None:
238238
"""Poll a resume trigger until data is available.
239239
240240
Args:

src/uipath/runtime/errors/contract.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
"""Standard error contract used across the runtime."""
22

33
from enum import Enum
4-
from typing import Optional
54

65
from pydantic import BaseModel
76

@@ -38,6 +37,6 @@ class UiPathErrorContract(BaseModel):
3837
# - Deployment: Configuration, licensing, or permission issues
3938
# - System: Unexpected internal errors or infrastructure issues
4039

41-
status: Optional[int] = (
40+
status: int | None = (
4241
None # HTTP status code, if relevant (e.g., when forwarded from a web API)
4342
)

src/uipath/runtime/errors/exception.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
import sys
44
import traceback
5-
from typing import Any, Optional
5+
from typing import Any
66

77
from uipath.runtime.errors.codes import UiPathErrorCode
88
from uipath.runtime.errors.contract import UiPathErrorCategory, UiPathErrorContract
@@ -17,7 +17,7 @@ def __init__(
1717
title: str,
1818
detail: str,
1919
category: UiPathErrorCategory = UiPathErrorCategory.UNKNOWN,
20-
status: Optional[int] = None,
20+
status: int | None = None,
2121
prefix: str = "Python",
2222
include_traceback: bool = True,
2323
):
@@ -42,13 +42,13 @@ def __init__(
4242
)
4343
super().__init__(detail)
4444

45-
def _extract_http_status(self) -> Optional[int]:
45+
def _extract_http_status(self) -> int | None:
4646
"""Extract HTTP status code from the exception chain if present."""
4747
exc_info = sys.exc_info()
4848
if not exc_info or len(exc_info) < 2 or exc_info[1] is None:
4949
return None
5050

51-
exc: Optional[BaseException] = exc_info[1] # Current exception being handled
51+
exc: BaseException | None = exc_info[1] # Current exception being handled
5252
while exc is not None:
5353
if hasattr(exc, "status_code"):
5454
return exc.status_code
@@ -85,7 +85,7 @@ def __init__(
8585
title: str,
8686
detail: str,
8787
category: UiPathErrorCategory = UiPathErrorCategory.UNKNOWN,
88-
status: Optional[int] = None,
88+
status: int | None = None,
8989
prefix: str = "Python",
9090
include_traceback: bool = True,
9191
):

src/uipath/runtime/events/base.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
"""Base classes for UiPath runtime events."""
22

33
from enum import Enum
4-
from typing import Any, Optional
4+
from typing import Any
55

66
from pydantic import BaseModel, ConfigDict, Field
77

@@ -21,10 +21,10 @@ class UiPathRuntimeEvent(BaseModel):
2121
model_config = ConfigDict(arbitrary_types_allowed=True)
2222

2323
event_type: UiPathRuntimeEventType
24-
execution_id: Optional[str] = Field(
24+
execution_id: str | None = Field(
2525
default=None, description="The runtime execution id associated with the event"
2626
)
27-
metadata: Optional[dict[str, Any]] = Field(
27+
metadata: dict[str, Any] | None = Field(
2828
default=None, description="Additional event context"
2929
)
3030

src/uipath/runtime/events/state.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
"""Events related to agent messages and state updates."""
22

3-
from typing import Any, Optional
3+
from typing import Any
44

55
from pydantic import Field
66

@@ -62,7 +62,7 @@ class UiPathRuntimeStateEvent(UiPathRuntimeEvent):
6262
"""
6363

6464
payload: dict[str, Any] = Field(description="Framework-specific state update")
65-
node_name: Optional[str] = Field(
65+
node_name: str | None = Field(
6666
default=None, description="Name of the node/agent that caused this update"
6767
)
6868
event_type: UiPathRuntimeEventType = Field(
Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
"""Execution context tracking for logging."""
22

33
from contextvars import ContextVar
4-
from typing import Optional
54

65
# Context variable to track current execution_id
7-
current_execution_id: ContextVar[Optional[str]] = ContextVar(
6+
current_execution_id: ContextVar[str | None] = ContextVar(
87
"current_execution_id", default=None
98
)

src/uipath/runtime/logging/_interceptor.py

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import logging
44
import os
55
import sys
6-
from typing import Optional, TextIO, Union, cast
6+
from typing import TextIO, cast
77

88
from uipath.runtime.logging._context import current_execution_id
99
from uipath.runtime.logging._filters import (
@@ -21,12 +21,12 @@ class UiPathRuntimeLogsInterceptor:
2121

2222
def __init__(
2323
self,
24-
min_level: Optional[str] = "INFO",
25-
dir: Optional[str] = "__uipath",
26-
file: Optional[str] = "execution.log",
27-
job_id: Optional[str] = None,
28-
execution_id: Optional[str] = None,
29-
log_handler: Optional[logging.Handler] = None,
24+
min_level: str | None = "INFO",
25+
dir: str | None = "__uipath",
26+
file: str | None = "execution.log",
27+
job_id: str | None = None,
28+
execution_id: str | None = None,
29+
log_handler: logging.Handler | None = None,
3030
):
3131
"""Initialize the log interceptor.
3232
@@ -56,11 +56,11 @@ def __init__(
5656
self.original_stdout = cast(TextIO, sys.stdout)
5757
self.original_stderr = cast(TextIO, sys.stderr)
5858

59-
self.log_handler: Union[
60-
UiPathRuntimeFileLogsHandler,
61-
logging.StreamHandler[TextIO],
62-
logging.Handler,
63-
]
59+
self.log_handler: (
60+
UiPathRuntimeFileLogsHandler
61+
| logging.StreamHandler[TextIO]
62+
| logging.Handler
63+
)
6464

6565
if log_handler:
6666
self.log_handler = log_handler
@@ -82,7 +82,7 @@ def __init__(
8282
self.log_handler.setLevel(self.numeric_min_level)
8383

8484
# Add execution context filter if execution_id provided
85-
self.execution_filter: Optional[logging.Filter] = None
85+
self.execution_filter: logging.Filter | None = None
8686
if execution_id:
8787
self.execution_filter = UiPathRuntimeExecutionFilter(execution_id)
8888
self.log_handler.addFilter(self.execution_filter)

src/uipath/runtime/result.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
"""Result of an execution with status and optional error information."""
22

33
from enum import Enum
4-
from typing import Any, Optional, Union
4+
from typing import Any
55

66
from pydantic import BaseModel, Field
77

@@ -21,10 +21,10 @@ class UiPathRuntimeStatus(str, Enum):
2121
class UiPathRuntimeResult(UiPathRuntimeEvent):
2222
"""Result of an execution with status and optional error information."""
2323

24-
output: Optional[Union[dict[str, Any], BaseModel]] = None
24+
output: dict[str, Any] | BaseModel | None = None
2525
status: UiPathRuntimeStatus = UiPathRuntimeStatus.SUCCESSFUL
26-
trigger: Optional[UiPathResumeTrigger] = None
27-
error: Optional[UiPathErrorContract] = None
26+
trigger: UiPathResumeTrigger | None = None
27+
error: UiPathErrorContract | None = None
2828

2929
event_type: UiPathRuntimeEventType = Field(
3030
default=UiPathRuntimeEventType.RUNTIME_RESULT, frozen=True

0 commit comments

Comments
 (0)