From 26dec1202785bcb2b20eae5749f6bd7289d16e85 Mon Sep 17 00:00:00 2001 From: mateo <277851410+mateo-berri@users.noreply.github.com> Date: Wed, 4 Nov 2026 08:06:11 +0000 Subject: [PATCH] refactor: keep media guard cast rather than trade it for new suppressions Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> --- .../litellm_core_utils/prompt_templates/common_utils.py | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/litellm/litellm_core_utils/prompt_templates/common_utils.py b/litellm/litellm_core_utils/prompt_templates/common_utils.py index 672debcbc7d..f48a42963cf 100644 --- a/litellm/litellm_core_utils/prompt_templates/common_utils.py +++ b/litellm/litellm_core_utils/prompt_templates/common_utils.py @@ -18,7 +18,6 @@ from types import MappingProxyType from typing import TYPE_CHECKING, Any, Final, Literal, TypeAlias, TypeVar, cast from pydantic import TypeAdapter, ValidationError -from typing_extensions import TypeIs # noqa: TID251 # TypeIs reaches typing only on 3.13 import litellm from litellm import verbose_logger @@ -448,11 +447,7 @@ def _tpm_embedding_leaf(value: object) -> _TPMMediaProjection: return _TPMMediaProjection("" if media else value, media) -def _is_json_array( - value: object, -) -> TypeIs[ # guard-ok: validates the exact list and tuple types # mutable-ok: JSON input arrays are mutable - list[object] | tuple[object, ...] -]: +def _is_json_array(value: object) -> bool: return isinstance(value, (list, tuple)) @@ -468,7 +463,7 @@ def split_embedding_media_for_tpm(value: object) -> tuple[object, tuple[Mapping[ def embedding_input_is_all_media(value: object) -> bool: - items: Final = value if _is_json_array(value) else (value,) + items: Final = cast(Sequence[object], value) if _is_json_array(value) else (value,) # cast-ok: JSON input array return all(_tpm_embedding_leaf(item).media for item in items)