From e2063c04b292b8c314e3f1df6e801132c88631e1 Mon Sep 17 00:00:00 2001 From: liming Date: Thu, 27 Aug 2026 18:41:47 +0800 Subject: [PATCH] fix(cost): build unique model names without mutable accumulators The type-discipline gate counts list/set annotations as LIT001 and un-Final assignments as LIT010. Dedup via tuple(dict.fromkeys(...)). Co-authored-by: Cursor --- litellm/cost_calculator.py | 22 +++++++++------------- 1 file changed, 9 insertions(+), 13 deletions(-) diff --git a/litellm/cost_calculator.py b/litellm/cost_calculator.py index 7514878eca3..3a4483bd6f4 100644 --- a/litellm/cost_calculator.py +++ b/litellm/cost_calculator.py @@ -328,19 +328,15 @@ def _published_token_rate( def _unique_model_names(*names: str | None) -> tuple[str, ...]: - unique: list[str] = [] - seen: set[str] = set() - for name in names: - if not isinstance(name, str) or not name or name in seen: - continue - seen.add(name) - unique.append(name) - if "/" in name: - tail: Final = name.split("/", 1)[1] - if tail and tail not in seen: - seen.add(tail) - unique.append(tail) - return tuple(unique) + return tuple( + dict.fromkeys( + part + for name in names + if isinstance(name, str) and name + for part in ((name,) if "/" not in name else (name, name.split("/", 1)[1])) + if part + ) + ) def _cost_map_rate(key: str | None, field: str) -> float | None: