chore: enable the perflint and comprehension ruff rules - #381
Draft
cloudsmith-iduffy wants to merge 1 commit into
Draft
chore: enable the perflint and comprehension ruff rules#381cloudsmith-iduffy wants to merge 1 commit into
cloudsmith-iduffy wants to merge 1 commit into
Conversation
Select PERF and C4. Rewrite the flagged loops as comprehensions and extend() calls. Ignore PERF203: the flagged try/except loops are fault-tolerant by design. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
cloudsmith-iduffy
force-pushed
the
lint/perf-lint-rules
branch
from
August 21, 2026 23:40
1e64bb3 to
2de7450
Compare
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.
Description
Ruff can catch a handful of slow Python patterns for us, so this turns on two of its rule groups:
PERF) — flags loop patterns that do more work than they need to, like building a list with.append()in a loop when a comprehension would doC4) — flags unnecessary or roundabout comprehensions, like wrapping something in a list comprehension that's already a listThen it fixes everything they flagged: mostly table-building loops in the
list,repos,dependenciesanddownloadcommands rewritten as comprehensions, a couple of hand-rolled dicts replaced withdict.fromkeys()/ a dict comprehension, and one comprehension that was a no-op deleted outright.To be honest about the motivation: none of these rewrites make the CLI measurably faster today — they're microseconds on loops of ~30 rows, so there are no flame graphs or benchmarks here. The point is the guard. The credential helpers now run on every docker/npm request, and I'd rather have the linter shout before an accidentally slow loop lands in one of those paths than find it in a profile later. Both rules run in pre-commit and in CI via the existing ruff hook, so there's nothing new to set up.
One rule from the group is deliberately switched off:
try/exceptinside a loop. All four places it flagged use theexceptas actual control flow — for example the credential chain trying each provider in turn and moving on when one fails. Restructuring those to save nanoseconds would make the code worse.Type of Change