mirror of
https://github.com/BerriAI/litellm.git
synced 2026-11-16 09:22:22 +00:00
type_check_gate: cast the response_format mapping instead of narrowing it
Three attempts at this did not clear the ceiling. Narrowing an `object` to
`Mapping` or to `dict` with isinstance leaves every `.get()` on it partially
unknown, so the errors move rather than go away, and putting the ignore on the
branch did not fit in 120 columns.
`cast("dict[str, object]", value)` gives the value a known type instead, which
leaves `get()` returning `object | None` and the file back at its baseline
count. Two suppressions remain, each stating what it covers: the cast, and the
call site where `value` comes out of the untyped `non_default_params` loop.
164 tests pass and the strict, type-discipline and test-quality gates are all
within their ceilings
This commit is contained in:
parent
f2d4306433
commit
eafae88742
1 changed files with 4 additions and 4 deletions
|
|
@ -11,7 +11,7 @@ import time
|
|||
import uuid
|
||||
from collections.abc import AsyncIterator, Iterator, Mapping, Sequence
|
||||
from types import MappingProxyType
|
||||
from typing import TYPE_CHECKING, Any, Final
|
||||
from typing import TYPE_CHECKING, Any, Final, cast
|
||||
|
||||
import httpx
|
||||
|
||||
|
|
@ -55,8 +55,8 @@ class GigaChatError(BaseLLMException):
|
|||
def _is_supported_response_format(value: object) -> bool:
|
||||
if not isinstance(value, Mapping):
|
||||
return False
|
||||
response_format_type: Final = value.get("type") # pyright: ignore[reportUnknownMemberType] # bare Mapping
|
||||
return response_format_type in (None, "text", "json_schema")
|
||||
response_format: Final = cast("dict[str, object]", value) # cast-ok: the provider sends a JSON object
|
||||
return response_format.get("type") in (None, "text", "json_schema")
|
||||
|
||||
|
||||
class GigaChatConfig(BaseConfig):
|
||||
|
|
@ -216,7 +216,7 @@ class GigaChatConfig(BaseConfig):
|
|||
]
|
||||
optional_params["function_call"] = {"name": schema_name}
|
||||
optional_params["_structured_output"] = True
|
||||
elif not _is_supported_response_format(value):
|
||||
elif not _is_supported_response_format(value): # pyright: ignore[reportUnknownArgumentType] # value
|
||||
from litellm.utils import UnsupportedParamsError
|
||||
|
||||
if litellm.drop_params is not True and drop_params is not True:
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue