fix(opentelemetry): use separate hashable_guardrail_mode to satisfy mypy

The previous reassignment of guardrail_mode to a tuple tripped mypy
because the variable inferred type from .get() is
GuardrailEventHooks | list[GuardrailEventHooks] | GuardrailMode | None,
which does not include tuple. Use a separately-named Any-typed binding
for the hashable form passed to _emit_once, preserving the original
runtime fix and keeping mypy green.
This commit is contained in:
Tai An 2026-05-27 18:14:38 -07:00
parent f6d117c498
commit cecc20eeba

View file

@ -1570,14 +1570,17 @@ class OpenTelemetry(OTELGenAISemconvMixin, CustomLogger):
# (e.g. ``mode: ["pre_call", "post_call"]``); ``_emit_once``
# requires hashable scope parts, so normalize lists to tuples.
guardrail_mode = guardrail_information.get("guardrail_mode")
if isinstance(guardrail_mode, list):
guardrail_mode = tuple(guardrail_mode)
hashable_guardrail_mode: Any = (
tuple(guardrail_mode)
if isinstance(guardrail_mode, list)
else guardrail_mode
)
if not self._emit_once(
kwargs,
"guardrail",
guardrail_information.get("guardrail_name"),
start_time_float,
guardrail_mode,
hashable_guardrail_mode,
):
continue