Skip to content

chore: enable the perflint and comprehension ruff rules - #381

Draft
cloudsmith-iduffy wants to merge 1 commit into
lint/ban-heavy-module-level-importsfrom
lint/perf-lint-rules
Draft

chore: enable the perflint and comprehension ruff rules#381
cloudsmith-iduffy wants to merge 1 commit into
lint/ban-heavy-module-level-importsfrom
lint/perf-lint-rules

Conversation

@cloudsmith-iduffy

@cloudsmith-iduffy cloudsmith-iduffy commented Aug 21, 2026

Copy link
Copy Markdown
Contributor

Description

Ruff can catch a handful of slow Python patterns for us, so this turns on two of its rule groups:

  • perflint (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 do
  • flake8-comprehensions (C4) — flags unnecessary or roundabout comprehensions, like wrapping something in a list comprehension that's already a list

Then it fixes everything they flagged: mostly table-building loops in the list, repos, dependencies and download commands rewritten as comprehensions, a couple of hand-rolled dicts replaced with dict.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/except inside a loop. All four places it flagged use the except as 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

  • Bug fix
  • New feature
  • Breaking change
  • Documentation update
  • Refactoring
  • Other (please describe)

@cloudsmith-iduffy cloudsmith-iduffy changed the title chore(no-ticket): enable the perflint and comprehension ruff rules chore: enable the perflint and comprehension ruff rules Aug 21, 2026
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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

1 participant