mirror of
https://github.com/BerriAI/litellm.git
synced 2026-11-15 09:12:18 +00:00
fix(prometheus): type the custom-label helpers as Mapping so TypedDicts are accepted
The combination helpers took `dict | None`, but their callers hold TypedDicts: the fallback emitters and the proxy failure hook pass a StandardLoggingMetadata, and set_llm_deployment_failure_metrics passes a StandardLoggingPayload. A TypedDict is not assignable to a bare `dict`, so basedpyright reported four reportArgumentType errors. That rule is at its ceiling in basedpyright-code-budget.json, so the lint job failed. Both helpers only read - `.get()` and `.items()` - so `Mapping[str, object]` is the honest contract and accepts TypedDicts, plain dicts and the payload types alike. The isinstance guards check Mapping to match, which keeps the same runtime behaviour for non-mapping input. reportArgumentType in this file is back to the base count of 22, and both gates pass locally: `type_discipline_gate.py` reports every LIT rule within its ceiling.
This commit is contained in:
parent
8b7605fa38
commit
3e504e7ec9
1 changed files with 4 additions and 4 deletions
|
|
@ -4264,7 +4264,7 @@ def get_custom_labels_from_metadata(metadata: dict) -> dict[str, str]:
|
|||
|
||||
|
||||
def _get_combined_custom_metadata_from_standard_logging_payload(
|
||||
standard_logging_payload: dict | None,
|
||||
standard_logging_payload: Mapping[str, object] | None,
|
||||
) -> dict[str, object]:
|
||||
"""
|
||||
Combine the metadata sources that can supply custom Prometheus labels.
|
||||
|
|
@ -4274,19 +4274,19 @@ def _get_combined_custom_metadata_from_standard_logging_payload(
|
|||
via custom_prometheus_metadata_labels configuration.
|
||||
"""
|
||||
return _get_combined_custom_metadata_from_standard_logging_metadata(
|
||||
standard_logging_payload.get("metadata") if isinstance(standard_logging_payload, dict) else None
|
||||
standard_logging_payload.get("metadata") if isinstance(standard_logging_payload, Mapping) else None
|
||||
)
|
||||
|
||||
|
||||
def _get_combined_custom_metadata_from_standard_logging_metadata(
|
||||
standard_logging_metadata: dict | None,
|
||||
standard_logging_metadata: Mapping[str, object] | None,
|
||||
) -> dict[str, object]:
|
||||
"""
|
||||
Same combination, for emitters holding the standard logging metadata itself
|
||||
rather than a whole payload: the fallback emitters and the proxy failure hook
|
||||
build it with StandardLoggingPayloadSetup.get_standard_logging_metadata.
|
||||
"""
|
||||
if not isinstance(standard_logging_metadata, dict):
|
||||
if not isinstance(standard_logging_metadata, Mapping):
|
||||
return {}
|
||||
|
||||
requester_metadata: Final = standard_logging_metadata.get("requester_metadata")
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue