refactor(lint): apply every safe ruff autofix and zero 28 strict-rule budgets - #35495
Merged
Merged
Conversation
…et the lint budgets
Contributor
|
Too many files changed for review. ( |
Codecov Report❌ Patch coverage is 📢 Thoughts on this report? Let us know! |
… budgets About 35,000 fixes ruff marks safe across 32 rules (UP006/UP045/UP007 modern annotations, UP032 f-strings, SIM114/SIM118, RET501, and friends), removal of the 1,296 typing imports the rewrite orphaned, and hand fixes for what the fixers could not see: five star-import freeloaders of typing names, two F823 late-import annotations, the /get/config/list introspection crash on types.UnionType, redundant function-local RoleMappings imports in ui_sso.py that shadowed the module-level name once the annotation lost its quotes, and one FURB168 tautology. B009/B010/PIE804/RUF019 are excluded on purpose: their safe fixes rewrite getattr/setattr/**-splat/key-in-dict escape hatches into forms basedpyright then rejects (283 new errors measured), so their budgets stay at base values. ruff-strict-budget.json drops by 39,579 this commit (39,968 across the branch) with 28 rules at an actual 0 and 9 more sharply down. type-discipline-budget.json ratchets LIT002/LIT006/LIT009 down; LIT001 moves to the now-honest total: the checker matches the spelling `set` but not the alias `Set`, so the 160 typing.Set annotations rewritten to set[...] were always mutable-set annotations and only now count.
Contributor
Author
…itellm_up035_abc_imports # Conflicts: # litellm/llms/bedrock/base_aws_llm.py # litellm/proxy/proxy_cli.py # litellm/proxy/proxy_server.py # litellm/repositories/model_repository.py # litellm/router.py
Contributor
Author
Contributor
Author
|
bugbot run |
Contributor
There was a problem hiding this comment.
✅ Bugbot reviewed your changes and found no new issues!
Comment @cursor review or bugbot run to trigger another review on this PR
Reviewed by Cursor Bugbot for commit 85f367b. Configure here.
tin-berri
approved these changes
Aug 1, 2026
This was referenced Aug 2, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
TLDR
Problem this solves:
How it solves it:
collections.abcRelevant issues
Linear ticket
Pre-Submission checklist
Please complete all items before asking a LiteLLM maintainer to review your PR
@greptileaito re-request a review after pushing changes)The sweep is guarded by the strict-rule gate itself (
scripts/ruff_strict_gate.pyfails CI on the first reintroduced violation of any zeroed rule once this merges and becomes the base), and the one behavioral regression the sweep surfaced (annotation introspection onX | None) is covered by the existingtest_get_config_list_*suite, which fails with the AttributeError if the introspection fix is removed, plus the updatedtest_customer_routes_declare_response_modelexpectationDelays in PR merge?
If you're seeing a delay in your PR being merged, ping the LiteLLM Team on Slack (#pr-review).
Screenshots / Proof of Fix
All "after" legs captured on a live proxy at the branch head
85f367b545(python litellm/proxy/proxy_cli.py --config litellm/proxy/dev_config.yaml, port 27833), hitting real provider APIs. The "before" leg proxy runslitellm_internal_stagingatb1fd20f4cd(port 26991)All three LLM endpoints against real providers:
DB-backed management routes:
The one runtime surface the sweep touched:
/config/listintrospects the rewritten annotations. Both legs return 200; the nestedfield_typestrings show the annotations actually changed at runtime. Without theUnionTypehand-fix in this push, the after leg 500s withAttributeError: 'types.UnionType' object has no attribute '__name__'(that is whattest_get_config_list_*now guards)The ratchet doing its job (simulating the post-merge world by pointing the gate's base at this branch):
Type
🧹 Refactoring
Changes
Two mechanical passes and a handful of hand fixes for what the fixers could not see
Commit
397e8e4918(the original scope):ruff check litellm --config ruff-strict.toml --select UP035 --fixmoved every abc-movable name (Mapping,Sequence,Iterable,Callable,Generator, and friends) fromtypingtocollections.abcacross 321 files, plus a scoped I001 re-sortCommit
b604e2b20cextends that to every safely auto-fixable rule.ruff --fixover 32 rules applied about 35,000 fixes ruff marks safe (UP006List[x]->list[x],UP045Optional[x]->x | None,UP007Union->|,UP037quote removal,UP032f-strings,RUF010f-string conversions,PIE790,SIM114,SIM118,RET501, and friends). A targeted pass then removed the 1,296typingimports the rewrite orphaned (filtered totyping.*names only, so no unrelated F401 removals), and 16 dead typing imports shielded by per-file F401 ignores inmain.py,utils.py,proxy_server.py, andproxy/utils.pywere removed by hand after confirming their only remaining "usages" were docstringsHand fixes for fallout the fixers could not see:
Optional/Dict/Listthroughfrom litellm.proxy._types import *(F403/F405 are ignored repo-wide, so no linter sees this); their usages are now spelled with builtins and an AST scan asserts zero remaining star-freeloaded typing names acrosslitellm/,tests/, andenterprise//config/listintrospection crashed onX | None(types.UnionTypehas no__name__) and itsorigin is Unionchecks missed the new union form; both handleUnionTypenowui_sso.py, unquotingOptional["RoleMappings"]exposed two redundant function-localRoleMappingsimports that shadowed the module-level import and left the new annotation statically unbound; the local imports are removedarg is not None and not (arg is None)), collapsed to a single checktyping.Optionalorphan inbedrock/chat/__init__.pythe import pass missed, removedMerge commit
85f367b545bringslitellm_internal_stagingback in and re-applies the sweep to the merged-in code (the sameruff --fixpass plus the orphaned-typing-import removal), so the zeroed rules stay at an actual 0 after the merge. The five conflicted files were resolved by taking the incoming side's logic and re-running the sweep over it; every merge-touched module was import-smoke-tested and its mapped test files passFour fixable rules are excluded on purpose.
B009/B010(getattr(x, "attr")/setattr(...)to direct attribute access),PIE804(f(**{...})to keyword arguments), andRUF019("k" in d and d["k"]tod.get("k")) have "safe" fixes that are runtime-neutral but convert type-checker escape hatches into static errors: applying their 326 fixes added 283 basedpyright errors (226reportAttributeAccessIssue, 44reportCallIssue, 13reportTypedDictNotRequiredAccessfrom narrowing loss on later lines). Those fixes were applied, measured, and reverted; the four budgets stay at base values. Also excluded:RUF100(its unused-noqa verdicts are config-relative, so a strict-config fix would strip directives the main config needs) and blanket F401 removal (import side effects; only the typing names the rewrite itself orphaned were removed)ruff-strict-budget.jsonis ratcheted by 39,579 inb604e2b20c(39,968 across the branch). 28 rules now sit at an actual 0 (UP006,UP008,UP012,UP018,UP024,UP034,UP035,UP045,I001,RUF010,RUF023,RUF051,PIE790,PIE800,PLC0208,PLR0402,PLR1711,PLR1730,PLR2044,PYI030,PYI041,PYI064,RET501,SIM114,TC005,B033,FURB136,FURB168), so once this merges the gate fails on the first new violation of any of them with no offsetting possible. 9 partially-fixable rules dropped sharply:UP0072526 -> 66,TID2512649 -> 1170,SIM118114 -> 44,UP032626 -> 1,UP037104 -> 2,RUF02285 -> 6,FURB18852 -> 1,RUF0468 -> 4,C901down 2. Net effect on basedpyright: 144 fewer errors than basetype-discipline-budget.jsonmoves too: LIT002 -19, LIT006 -1, LIT009 -2 via the official--updateratchet, and LIT001 goes 23191 -> 23350 by hand. That last one is a ceiling raise, so to be explicit about why: the LIT001 checker pattern-matches the spellingsetbut not the aliasSet, so the 160typing.Set[...]annotations this sweep rewrote toset[...]were always mutable-set annotations and only now count. The debt is pre-existing, the measurement got honest, and the new limit sits exactly at the measured total with zero headroom (the old limit had 1). Teaching the checker theSetalias instead was considered and rejected: after this sweepcollections.abc.Set(the read-only ABC) is the only UP035-clean spelling of an abstract set, and a name-based checker cannot tell it apart fromtyping.SetFinal Attestation
Note
Low Risk
Changes are mechanical typing and lint-budget ratchets with targeted runtime fixes for config introspection; proxy/LLM paths were smoke-tested per the PR description.
Overview
This PR applies safe ruff autofixes across a large swath of
litellm/(~35k+ edits):Optional[T]→T | None,List/Dict→list/dict,Union→|, ABC imports moved tocollections.abc, f-strings, and similar style-only cleanups. Behavior is intended to stay the same; the diff is overwhelmingly annotation and import spelling.Hand fixes address what the fixers could not handle safely:
/config/list(and related introspection) now treatstypes.UnionType(X | None) sofield_typestrings likefloat | Nonework instead of 500ing; star-import typing freeloaders are removed; a few forward-ref / import-order and tautology fixes from the sweep.Lint policy ratchets 28 strict-rule budgets to 0 (e.g.
UP006,UP035,UP045,I001) so CI blocks reintroducing those patterns; four “safe” rules stay excluded where fixes break type-checking.type-discipline-budget.jsonis updated (including an honest LIT001 ceiling aftertyping.Set[...]→set[...]).Reviewed by Cursor Bugbot for commit 85f367b. Bugbot is set up for automated code reviews on this repo. Configure here.