From 68e93eae6a03ee709d598540ba315974465ecad6 Mon Sep 17 00:00:00 2001 From: lzhan011 <35493221+lzhan011@users.noreply.github.com> Date: Mon, 5 Oct 2026 18:40:37 -0500 Subject: [PATCH] style(cache): give the deferred import's noqa a reason, as the gate requires `lint` was still red after the format fix, on a different rule this time: FAIL: LIT-rule totals exceed their limit (base 1238cfe90f): LIT003: total 263 over limit 261 (this change added 1) litellm/_service_logger.py:345 LIT003 is `scripts/check_type_discipline.py`'s "noqa requires rule codes or a reason". The deferred import carried `# noqa: PLC0415` with no reason, so it counted against the budget; it now says why the import is deferred (a module-scope import would be circular, since redis_cache imports this module). Two things worth recording, both found by running the gate rather than guessing: * A first attempt put the explanation on its own comment line above the import. That line contained the word "noqa", which `scan_comments` reads as a *bare* suppression -- so the explanatory comment created a second LIT003 instead of clearing the first. The reason has to live on the suppression line itself. * `ruff check` then wanted I001 on the longer line, and its fix wraps the import in parentheses with the comment on the imported name. `ruff format --check`, `ruff check` and the LIT003 scan are all clean on the three files now, and tests/unit/caching/test_redis_cache.py still reports 100 passed. --- litellm/_service_logger.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/litellm/_service_logger.py b/litellm/_service_logger.py index 7688968b9dc..9f81e6bdb51 100644 --- a/litellm/_service_logger.py +++ b/litellm/_service_logger.py @@ -342,7 +342,9 @@ class ServiceLogging(CustomLogger): # than at each call site: `redis_cache` hands this hook an exception # from ~16 places and a new one must not be able to leak by being # written without the redaction. - from litellm.caching.redis_cache import redact_redis_error # noqa: PLC0415 + from litellm.caching.redis_cache import ( + redact_redis_error, # noqa: PLC0415 # redis_cache imports this module; a module-scope import would be circular + ) error_message = redact_redis_error(error) if isinstance(error, Exception) else error_message