The fastest, litest AI Gateway. Rust core with Python SDK. Call 100+ LLM APIs in OpenAI (or native) format with cost tracking, guardrails, load balancing, and logging [Bedrock, Azure, OpenAI, Anthropic, OpenAI, VertexAI, vLLM, Nvidia NIM]
Python ai-gatewayanthropicazure-openaibedrockgatewaylangchainlitellmllmllm-gatewayllmopsmcp-gatewayopenaiopenai-proxyrustrust-aivertex-ai
fix(lint): fix ruff/flake8 violations - unused imports, PLR0915, print statements (#21846)
Ishaan Jaff3278fee71445
diff --git a/litellm/proxy/litellm_pre_call_utils.py b/litellm/proxy/litellm_pre_call_utils.pyindex 1fd81eccfd0..089731c473d 100644--- a/litellm/proxy/litellm_pre_call_utils.py+++ b/litellm/proxy/litellm_pre_call_utils.py@@ -24,7 +24,6 @@ from litellm.proxy._types import (_SPECIAL_HEADERS_CACHE = frozenset(v.value.lower() for v in SpecialHeaders._member_map_.values())-from litellm.proxy.auth.route_checks import RouteChecksfrom litellm.router import Routerfrom litellm.types.llms.anthropic import ANTHROPIC_API_HEADERSfrom litellm.types.services import ServiceTypesdiff --git a/litellm/router.py b/litellm/router.pyindex 85fc7e90075..c6409ce1680 100644--- a/litellm/router.py+++ b/litellm/router.py@@ -1536,7 +1536,7 @@ class Router:)raise e- async def _acompletion_streaming_iterator(+ async def _acompletion_streaming_iterator( # noqa: PLR0915self,model_response: CustomStreamWrapper,messages: List[Dict[str, str]],diff --git a/litellm/router_strategy/complexity_router/evals/eval_complexity_router.py b/litellm/router_strategy/complexity_router/evals/eval_complexity_router.pyindex b16af353449..e671b97c575 100644--- a/litellm/router_strategy/complexity_router/evals/eval_complexity_router.py+++ b/litellm/router_strategy/complexity_router/evals/eval_complexity_router.py@@ -4,15 +4,16 @@ Evaluation suite for the ComplexityRouter.Tests the router's ability to correctly classify prompts into complexity tiers.Run with: python -m litellm.router_strategy.complexity_router.evals.eval_complexity_router"""-import json+import os++# Add parent to path for imports+import sys++# ruff: noqa: T201from dataclasses import dataclass-from enum import Enumfrom typing import List, Optional, Tuplefrom unittest.mock import MagicMock-# Add parent to path for imports-import sys-import ossys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__), "../../../../..")))from litellm.router_strategy.complexity_router.complexity_router import ComplexityRouter@@ -241,10 +242,10 @@ def run_eval() -> Tuple[int, int, List[dict]]:total = len(EVAL_CASES)failures = []- print("=" * 70)- print("COMPLEXITY ROUTER EVALUATION")- print("=" * 70)- print()+ print("=" * 70) # noqa: T201+ print("COMPLEXITY ROUTER EVALUATION") # noqa: T201+ print("=" * 70) # noqa: T201+ print() # noqa: T201for i, case in enumerate(EVAL_CASES, 1):tier, score, signals = router.classify(case.prompt, case.system_prompt)@@ -274,30 +275,29 @@ def run_eval() -> Tuple[int, int, List[dict]]:})# Print result- match_type = "exact" if is_exact_match else ("acceptable" if is_acceptable else "mismatch")- print(f"[{i:2d}] {status} | {case.description}")- print(f" Expected: {case.expected_tier.value:10s} | Got: {tier.value:10s} | Score: {score:+.3f}")+ print(f"[{i:2d}] {status} | {case.description}") # noqa: T201+ print(f" Expected: {case.expected_tier.value:10s} | Got: {tier.value:10s} | Score: {score:+.3f}") # noqa: T201if signals:- print(f" Signals: {', '.join(signals)}")+ print(f" Signals: {', '.join(signals)}") # noqa: T201if not is_pass:- print(f" Prompt: {case.prompt[:60]}...")- print()+ print(f" Prompt: {case.prompt[:60]}...") # noqa: T201+ print() # noqa: T201# Summary- print("=" * 70)- print(f"RESULTS: {passed}/{total} passed ({100*passed/total:.1f}%)")- print("=" * 70)+ print("=" * 70) # noqa: T201+ print(f"RESULTS: {passed}/{total} passed ({100*passed/total:.1f}%)") # noqa: T201+ print("=" * 70) # noqa: T201if failures:- print("\nFAILURES:")- print("-" * 70)+ print("\nFAILURES:") # noqa: T201+ print("-" * 70) # noqa: T201for f in failures:- print(f"Case {f['case']}: {f['description']}")- print(f" Expected: {f['expected']}, Got: {f['actual']} (score: {f['score']})")- print(f" Signals: {f['signals']}")+ print(f"Case {f['case']}: {f['description']}") # noqa: T201+ print(f" Expected: {f['expected']}, Got: {f['actual']} (score: {f['score']})") # noqa: T201+ print(f" Signals: {f['signals']}") # noqa: T201if f['acceptable']:- print(f" Acceptable: {f['acceptable']}")- print()+ print(f" Acceptable: {f['acceptable']}") # noqa: T201+ print() # noqa: T201return passed, total, failures@@ -309,13 +309,13 @@ def main():# Exit with error code if too many failurespass_rate = passed / totalif pass_rate < 0.80:- print(f"\n❌ EVAL FAILED: Pass rate {pass_rate:.1%} is below 80% threshold")+ print(f"\n❌ EVAL FAILED: Pass rate {pass_rate:.1%} is below 80% threshold") # noqa: T201sys.exit(1)elif pass_rate < 0.90:- print(f"\n⚠️ EVAL WARNING: Pass rate {pass_rate:.1%} is below 90%")+ print(f"\n⚠️ EVAL WARNING: Pass rate {pass_rate:.1%} is below 90%") # noqa: T201sys.exit(0)else:- print(f"\n✅ EVAL PASSED: Pass rate {pass_rate:.1%}")+ print(f"\n✅ EVAL PASSED: Pass rate {pass_rate:.1%}") # noqa: T201sys.exit(0)