Skip to content

Commit 01a125b

Browse files
authored
Merge pull request #3 from UiPath/fix/typing
fix: mypy errors
2 parents 9b56918 + feaa5a8 commit 01a125b

File tree

8 files changed

+28
-39
lines changed

8 files changed

+28
-39
lines changed

pyproject.toml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,9 @@ line-ending = "auto"
7676

7777
[tool.mypy]
7878
plugins = ["pydantic.mypy"]
79-
79+
mypy_path = "src"
80+
explicit_package_bases = true
81+
namespace_packages = true
8082
follow_imports = "silent"
8183
warn_redundant_casts = true
8284
warn_unused_ignores = true

src/uipath/runtime/logging/_filters.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ def filter(self, record: logging.LogRecord) -> bool:
2424
ctx_execution_id = current_execution_id.get()
2525
if ctx_execution_id == self.execution_id:
2626
# Inject execution_id into record for downstream handlers
27-
record.execution_id = self.execution_id # type: ignore[attr-defined]
27+
record.execution_id = self.execution_id
2828
return True
2929

3030
return False

src/uipath/runtime/logging/_interceptor.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -170,10 +170,10 @@ def _redirect_stdout_stderr(self) -> None:
170170
self._clean_all_handlers(stderr_logger)
171171

172172
# Use the min_level in the LoggerWriter to filter messages
173-
sys.stdout = LoggerWriter( # type: ignore[assignment]
173+
sys.stdout = LoggerWriter(
174174
stdout_logger, logging.INFO, self.numeric_min_level, self.original_stdout
175175
)
176-
sys.stderr = LoggerWriter( # type: ignore[assignment]
176+
sys.stderr = LoggerWriter(
177177
stderr_logger, logging.ERROR, self.numeric_min_level, self.original_stderr
178178
)
179179

File renamed without changes.

src/uipath/runtime/tracing/_utils.py

Lines changed: 14 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,12 @@
55
import os
66
import random
77
import uuid
8+
from collections.abc import Callable
89
from dataclasses import asdict, is_dataclass
910
from datetime import datetime, timezone
1011
from enum import Enum
1112
from os import environ as env
12-
from typing import Any, Callable, Dict, Optional
13+
from typing import Any, Dict, Mapping, Optional
1314
from zoneinfo import ZoneInfo
1415

1516
from opentelemetry.sdk.trace import ReadableSpan
@@ -20,35 +21,21 @@
2021

2122

2223
def get_supported_params(
23-
tracer_impl: Callable, params: Dict[str, Any]
24+
tracer_impl: Callable[..., Any],
25+
params: Mapping[str, Any],
2426
) -> Dict[str, Any]:
25-
"""Extract the parameters supported by the tracer implementation.
26-
27-
Args:
28-
tracer_impl: The tracer implementation function or callable
29-
params: Dictionary of parameters to check
30-
31-
Returns:
32-
Dictionary containing only parameters supported by the tracer implementation
33-
"""
34-
supported_params = {}
35-
if hasattr(tracer_impl, "__code__"):
36-
# For regular functions
37-
impl_signature = inspect.signature(tracer_impl)
38-
for param_name, param_value in params.items():
39-
if param_name in impl_signature.parameters and param_value is not None:
40-
supported_params[param_name] = param_value
41-
elif callable(tracer_impl):
42-
# For callable objects
43-
impl_signature = inspect.signature(tracer_impl.__call__)
44-
for param_name, param_value in params.items():
45-
if param_name in impl_signature.parameters and param_value is not None:
46-
supported_params[param_name] = param_value
47-
else:
27+
"""Extract the parameters supported by the tracer implementation."""
28+
try:
29+
sig = inspect.signature(tracer_impl)
30+
except (TypeError, ValueError):
4831
# If we can't inspect, pass all parameters and let the function handle it
49-
supported_params = params
32+
return dict(params)
5033

51-
return supported_params
34+
supported: Dict[str, Any] = {}
35+
for name, value in params.items():
36+
if value is not None and name in sig.parameters:
37+
supported[name] = value
38+
return supported
5239

5340

5441
def _simple_serialize_defaults(obj):

src/uipath/runtime/tracing/decorators.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,12 @@
1919
logger = logging.getLogger(__name__)
2020

2121

22-
def _default_input_processor() -> dict:
22+
def _default_input_processor() -> dict[str, Any]:
2323
"""Default input processor that doesn't log any actual input data."""
2424
return {"redacted": "Input data not logged for privacy/security"}
2525

2626

27-
def _default_output_processor() -> dict:
27+
def _default_output_processor() -> dict[str, Any]:
2828
"""Default output processor that doesn't log any actual output data."""
2929
return {"redacted": "Output data not logged for privacy/security"}
3030

src/uipath/runtime/tracing/processors.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
"""Custom span processors for UiPath execution tracing."""
22

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

55
from opentelemetry import context as context_api
66
from opentelemetry import trace
@@ -18,11 +18,11 @@ def on_start(
1818
"""Called when a span is started."""
1919
parent_span: Optional[Span]
2020
if parent_context:
21-
parent_span = trace.get_current_span(parent_context)
21+
parent_span = cast(Span, trace.get_current_span(parent_context))
2222
else:
23-
parent_span = trace.get_current_span()
23+
parent_span = cast(Span, trace.get_current_span())
2424

25-
if parent_span and parent_span.is_recording():
25+
if parent_span and parent_span.is_recording() and parent_span.attributes:
2626
execution_id = parent_span.attributes.get("execution.id")
2727
if execution_id:
2828
span.set_attribute("execution.id", execution_id)

src/uipath/runtime/tracing/span.py

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

33
from datetime import datetime
44
from os import environ as env
5-
from typing import Optional
5+
from typing import Any, Optional
66
from uuid import UUID
77

88
from pydantic import BaseModel, ConfigDict, Field
@@ -62,7 +62,7 @@ class UiPathRuntimeSpan(BaseModel):
6262
default_factory=lambda: env.get("UIPATH_JOB_KEY"), serialization_alias="JobKey"
6363
)
6464

65-
def to_dict(self) -> dict:
65+
def to_dict(self) -> dict[str, Any]:
6666
"""Convert the Span to a dictionary suitable for JSON serialization.
6767
6868
Returns a dict with PascalCase keys for UiPath API compatibility.

0 commit comments

Comments
 (0)