Skip to content

chore(lint): remove the LIT002 mutable-construction rule - #43971

Merged
mateo-berri merged 7 commits into
mainfrom
litellm_/remove-lit-002-296d65
Oct 1, 2026
Merged

mateo-berri merged 7 commits into
mainfrom
litellm_/remove-lit-002-296d65

Conversation

@yuneng-berri

@yuneng-berri yuneng-berri commented Oct 1, 2026 •

Copy link
Copy Markdown
Contributor

TLDR

Problem this solves:

  • LIT002 flags every list, dict, and set literal in the codebase
  • ~26.7k grandfathered hits plus ~1.4k # mutable-ok markers to silence it

How it solves it:

  • Removes the LIT002 rule, its helpers, tests, and budget entry
  • # mutable-ok now only suppresses LIT001
  • Deletes the markers that suppressed only LIT002, now stale under LIT013
  • Reformats files whose layout depended on those trailing comments

User Flow

Before: a contributor writing an ordinary list literal in litellm/ gets a lint violation

  1. They add acc: Final = [] and run python scripts/check_type_discipline.py <file>
  2. The checker prints a LIT002 "mutable list literal" violation and exits 1
  3. They either rewrite it or add a # mutable-ok: <reason> marker

After: the same line passes, and LIT001 still catches mutable types in annotations

  1. They add acc: Final = [] and run the same command
  2. No LIT002 violation is reported
  3. A # mutable-ok marker on that line is now reported as LIT013 (suppresses nothing)

Pre-Submission checklist

Please complete all items before asking a LiteLLM maintainer to review your PR

  • I have added meaningful tests
  • The handful of test files covering my change pass locally, e.g. uv run pytest tests/unit/<your_test_file>.py -v. Leave the suites (make test-unit-*, make test-unit) to CI: it finishes in ~15 minutes where a laptop takes an hour or more
  • My PR passes all required CI/CD checks (e.g., lint, schema.d.ts sync check, etc.)
  • My PR's scope is as isolated as possible; it only solves 1 specific problem
  • I have received a Greptile Confidence Score of at least 4/5 before requesting a maintainer review (Greptile reviews automatically once the PR is opened; only comment @greptileai to re-request a review after pushing changes)

Delays 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

Shared snippet:

printf 'from typing import Final\nacc: Final = []\nseed: Final = {}  # mutable-ok: seed\n' > snippet.py

Before (main at a76b59d)

  1. python3 scripts/check_type_discipline.py snippet.py
  2. Output, exit 1:
    snippet.py:2: LIT002 mutable list literal: this builds a collection that can be grown or rewritten. ...
    

After (bb5dfe3)

  1. python3 scripts/check_type_discipline.py snippet.py
  2. Output, exit 1, the stale marker is the only finding:
    snippet.py:3: LIT013 `# mutable-ok` suppresses nothing: no LIT001 violation on this line, so delete it
    
  3. python scripts/type_discipline_gate.py --base origin/main
    OK: every LIT rule is within its codebase ceiling (base origin/main)
    
  4. Every LIT rule count over litellm/ except LIT002 and LIT013 is identical on main and on this branch (LIT001 22133, LIT010 15974, LIT011 5460, LIT014 370, and so on). LIT013 goes from 9 to 6 because three of the removed markers were already flagged on main
  5. The parsed AST of every touched file matches main, except the checker, the gate, its test, and one docstring in team_callback_endpoints.py, so the marker removal and reformat change no runtime behavior
  6. make check passes on the merged tree
  7. The branch merges main at a76b59d. The four files that conflicted with main's litellm/proxy/engine to litellm/proxy/lens rename take main's version, and the markers main added on construction lines since then are removed the same way

Type

Refactoring
Infrastructure

Caveats (if any)

Low

  • Edits type-discipline-budget.json, which normally only the ratchet automation touches
    • Required: test_budget_covers_exactly_the_checker_rules asserts budget keys match checker rules
    • Only the LIT002 entry is deleted, no other limit changes
    • The non-required budget-ratchet check is red for this reason, since it flags any dropped entry
  • 367 files changed, nearly all comment removal plus ruff reformat of affected lines
  • Open PRs that added # mutable-ok on a construction line will fail the LIT013 gate once they merge main
    • Not fixable here; the fix on each PR is deleting the marker
  • Main's feat(ui): show daily token totals on the model leaderboard #44044 added two # mutable-ok markers on construction lines in litellm/proxy/management_endpoints/model_insights_endpoints.py after this branch last merged main
    • They become stale (LIT013) once this merges and a small follow-up removes them; the gate does not fail, since it counts the base with the same checker
  • Greptile's outside-diff finding (failed calls consume Lens budget, litellm/proxy/lens/inference.py) is about code main already has
    • This PR's diff against main in litellm/proxy/lens/ is comment removal only, with identical ASTs
  • Two non-required checks are red without this PR causing it
    • schema-migration fails on main too (main run at a76b59d)
    • osv-scan fails on every open PR right now

Final Attestation

  • The tests check the right things, including the edge cases, and regressions in the respective real-world customer use-cases are not possible after this PR

Note

Low Risk
Lint-only policy change with AST-equivalent edits; risk is contributor friction from LIT013 on branches that still carry obsolete # mutable-ok comments.

Overview
Removes the LIT002 type-discipline rule that flagged mutable list/dict/set literals across litellm/, along with its budget entry and related checker/tests (per PR scope). # mutable-ok now only suppresses LIT001 (mutable annotations/accumulators); stale markers that suppressed nothing are reported as LIT013.

The bulk of the diff is mechanical cleanup: delete thousands of # mutable-ok trailing comments (and minor reformatting where ruff depended on them) in caching, integrations, providers, proxy-adjacent core utils, and AGENTS.md guidance narrowed from “LIT001 or LIT002” to LIT001 only. A few sites (e.g. litellm/litellm_core_utils/tokenizer.py) keep # mutable-ok: [LIT001] where the rule still applies.

No intended runtime or API behavior change—only lint policy and comment hygiene.

Reviewed by Cursor Bugbot for commit bb5dfe3. Bugbot is set up for automated code reviews on this repo. Configure here.

Drop LIT002 from scripts/check_type_discipline.py along with its helpers,
its budget entry, its unit tests, and the AGENTS.md and gate docstring
mentions. `# mutable-ok` now only suppresses LIT001, so the markers that
only existed to silence LIT002 became LIT013 stale suppressions and are
removed. The files whose layout depended on those trailing comments are
reformatted with ruff format.

Every other LIT rule count is unchanged and the ASTs of all touched
litellm/ files match main apart from one docstring.
Restore the ~1.4k `# mutable-ok` markers stripped in the previous commit
so this PR only touches the checker, its tests, the budget, and docs.
Those markers no longer suppress anything, so `# mutable-ok` is exempt
from LIT013 until a follow-up strips them.
@greptile-apps

greptile-apps Bot commented Oct 1, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerConfidence Score: 5/5

[Low risk] Removes a linting rule from the codebase.

The PR appears safe to merge based on the changes against main

Findings

  1. P2 Budget edited on PR branch ▶

Summary

The PR removes the LIT002 mutable-construction check and its budget entry, makes mutable-ok suppress only LIT001, and removes obsolete markers across the codebase. The checked cleanup does not introduce a new actionable finding

Reviews (4) · Last reviewed commit: "Merge remote-tracking branch 'origin/mai..."

@@ -2,9 +2,6 @@
"LIT001": {
"limit": 22174
},
"LIT002": {
"limit": 26715
},
"LIT003": {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Budget edited on PR branch The repository’s contributor instructions say never to edit type-discipline-budget.json on a PR branch and to drop any such edit before opening the PR. This PR removes the LIT002 entry from that file. The checker and budget still need to agree, but this repository requirement must be satisfied before merging.

Context Used: AGENTS.md (source)

Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wait we have to remove this entry to you know remove the LIT lint check

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You’re right: removing LIT002 means its budget entry must also be removed. The checker and budget schema need to stay synchronized, so my earlier comment was incorrect.

@codspeed

codspeed Bot commented Oct 1, 2026 •

Copy link
Copy Markdown
Contributor

Merging this PR will not alter performance

✅ 31 untouched benchmarks


Comparing litellm_/remove-lit-002-296d65 (bb5dfe3) with main (259c166)1

Open in CodSpeed

Footnotes

  1. No successful run was found on main (a76b59d) during the generation of this report, so 259c166 was used instead as the comparison base. There might be some changes unrelated to this pull request in this report. ↩

@mateo-berri

Copy link
Copy Markdown
Contributor

@greptileai

@mateo-berri

Copy link
Copy Markdown
Contributor

bugbot run

@cursor cursor Bot left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Stale Bugbot comment from a previous run.

@greptile-apps

greptile-apps Bot commented Oct 1, 2026 •

Copy link
Copy Markdown
Contributor

Comments Outside Diff

These findings could not be posted inline.

  • P1 Failed calls consume Lens budget litellm/proxy/lens/inference.py:151 ▶

    Lens persists an estimated charge before inference, but reconciles it only after a successful response and parsing. If inference fails after the reservation, the estimate remains in spent and the job cost. Failed attempts can therefore exhaust the monthly Lens budget and block later analyses without producing a result.

…ines

Main renamed litellm/proxy/engine to litellm/proxy/lens and added 22 mutable-ok markers that only suppressed LIT002, across 10 files. Conflicted files take main's version with those markers removed, so the merged tree differs from main by comments only outside the checker, its test and the gate docstring.
@mateo-berri

Copy link
Copy Markdown
Contributor

@greptileai

1 similar comment
@mateo-berri

Copy link
Copy Markdown
Contributor

@greptileai

@mateo-berri

Copy link
Copy Markdown
Contributor

bugbot run

@cursor cursor Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ 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 bb5dfe3. Configure here.

@mateo-berri mateo-berri left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Thanks!

@mateo-berri
mateo-berri merged commit bba85f0 into main Oct 1, 2026
114 of 119 checks passed
@mateo-berri
mateo-berri deleted the litellm_/remove-lit-002-296d65 branch October 1, 2026 19:24
Rainmemery added a commit to Rainmemery/litellm that referenced this pull request Oct 6, 2026
After rebasing onto main (which removed the LIT002 mutable-construction
rule in BerriAI#43971), the '# mutable-ok' annotation on this line suppressed
nothing and tripped the LIT013 stale-suppression gate. The copy is a
deliberate rebinding, so annotate it as one.
doramirdor added a commit to doramirdor/litellm that referenced this pull request Oct 6, 2026
…aned

BerriAI#43971 removed the LIT002 mutable-construction rule, so the
`# mutable-ok` comments on the request headers and the request body no
longer suppress anything, and type_discipline_gate reports each as an
unused suppression (LIT013). The one on the tier_map dict still applies
and stays.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
devin-ai-integration Bot added a commit that referenced this pull request Oct 7, 2026
Main already retired LIT002 (#43971). This narrows LIT001 to mutable sequences and sets, so dict, Dict,
DefaultDict, OrderedDict, Counter, ChainMap, defaultdict and MutableMapping annotations are allowed, nested
list/set inside a mapping still trips, and the 945 mutable-ok suppressions that only covered mapping
annotations are deleted (LIT013 now flags them). AGENTS.md guidance updated to match

Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>

This branch is waiting to be deployed

1 waiting deployment
e2e-changed — bb5dfe30 Waiting Oct 1, 2026 by mateo-berri via oauth #2357
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants