Repository navigation
refactor(lint): allow dict and mapping annotations in LIT001 - #41100
devin-ai-integration[bot] wants to merge 12 commits into
Conversation
🤖 Devin AI EngineerI'll be helping with this pull request! Here's what you should know: ✅ I will automatically:
Note: I can only respond to comments from users who have write access to this repository. ⚙️ Control Options:
|
Codecov Report❌ Patch coverage is 📢 Thoughts on this report? Let us know! |
|
|
bugbot run |
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>
6b847ee to
22d584a
Compare
|
@greptileai review |
|
bugbot run |
Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
…m main Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
|
@greptileai review |
|
bugbot run |
Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
|
@greptileai review |
|
bugbot run |
Comments Outside DiffThese findings could not be posted inline.
|
|
@greptileai review. The three Lens Helm findings come from main commits merged in 0be8fd5; this PR diff vs merge base touches no helm or lens files |
…_dict_ban_v2 Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> # Conflicts: # litellm/types/decisions.py
|
@greptileai review |
Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
|
@greptileai review |
|
bugbot run |
|
@greptileai review |
Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
|
bugbot run |
Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
|
bugbot run |
Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
|
bugbot run |
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 d14859c. Configure here.
|
@greptileai review |
Relevant issues
Pre-Submission checklist
Please complete all items before asking a LiteLLM maintainer to review your PR
tests/test_litellm/directory, Adding at least 1 test is a hard requirementmake test-unitType
🧹 Refactoring
Changes
Main already retired LIT002 in #43971, so this PR is now the remaining half of the LIT002 cleanup: LIT001 stops flagging mapping annotations
So
x: dict[str, int]andpayload: MutableMapping[str, object]are clean, whilex: dict[str, list[int]]still trips on the nested list. The LIT001 message and docstring now recommendSequence/AbstractSet/tuple/frozensetinstead of also pushingMappingOnce dict is allowed, LIT013 flags every
# mutable-okthat only covered a mapping annotation as suppressing nothing, so 945 of them across 269 files are deleted. Those are comment-only edits; the eight test files that ruff format also touched were already unformatted on main and CI's scoped format check requires them cleanAGENTS.md: the LIT001 paragraph and the no-mutation convention now say plain
dictis fine (most of the ecosystem takes and returns dicts,MappingProxyTypeat every boundary costs more than it protects), prefer tuples over lists and frozensets over sets, prefer frozen dataclasses orReadOnlyTypedDicts for structured records, and never deep copy a value just to hand out an immutable view (the self-referential breadcrumbs deep copy that leaked memory is the motivating case)Why: the dict ban filled files with
# mutable-oknoise, pushed defensive deep copies and MappingProxyType round trips at every library boundary, and made the LIT budget ratchet turn unrelated rebases red because almost every real PR adds a dict literal. The narrower rule on sequences and sets keeps the part of the policy that cost littleNot in scope: caches that shallow copy on every mutation and per-folder scoping of the rule, both discussed as follow ups
Tests
tests/unit/test_check_type_discipline.pygainstest_mapping_annotations_are_allowed(dict, Dict, DefaultDict, MutableMapping, defaultdict, OrderedDict, string forward ref all clean;dict[str, list[int]]still flagged) and the existing LIT001 cases switch their dict fixtures to list/set so they keep testing the ruleReview state
Greptile 5/5 and Bugbot no new issues at 82ba2a2, both re-triggered on each push. Required checks green. rust-wheel is red on main too: tests/test_litellm_rust/test_traces.py fails to collect with
No module named scripts, and this PR touches nothing under tests/test_litellm_rust, scripts/seed_tracing_fixtures.py, or the MakefileLink to Devin session: https://app.devin.ai/sessions/db4d9941966544268db903dcf292d47b
Open in Devin Desktop: https://app.devin.ai/desktop/session/db4d9941966544268db903dcf292d47b?variant=devin
Note
Low Risk
Lint policy and comment cleanup only; runtime logic is unchanged aside from narrower LIT001 enforcement on sequences and sets.
Overview
LIT001 no longer treats mapping types as mutable collections:
dict,Dict,MutableMapping,defaultdict,OrderedDict, and similar annotations are allowed, while nested mutable containers (e.g.dict[str, list[int]]) still fail on the innerlist/set.Because many
# mutable-okcomments only existed to excuse dict-typed parameters and locals, this PR strips hundreds of those suppressions (and a few related# rebind-oknotes) across harness, integrations, LLM providers, caching, and enterprise code—comment-only in those files, with no intended behavior change.AGENTS.md is updated to match: plain
dictis acceptable at boundaries; prefer tuples/frozensets over lists/sets; use frozen dataclasses orReadOnlyTypedDicts for structured records; avoid deep copies solely to expose an immutable view.Unit coverage adds
test_mapping_annotations_are_allowedand adjusts existing LIT001 fixtures to use list/set where dict was previously the example.Reviewed by Cursor Bugbot for commit d14859c. Bugbot is set up for automated code reviews on this repo. Configure here.