chore: enable the perflint and comprehension ruff rules - #381
Merged
cloudsmith-iduffy merged 1 commit intoAug 25, 2026
Merged
Conversation
cloudsmith-iduffy
force-pushed
the
lint/perf-lint-rules
branch
from
August 21, 2026 23:40
1e64bb3 to
2de7450
Compare
cloudsmith-iduffy
marked this pull request as ready for review
August 24, 2026 06:51
Contributor
There was a problem hiding this comment.
Pull request overview
This pull request enables Ruff’s C4 and PERF rules and applies collection-building refactors across the CLI and core code.
Changes:
- Enables
C4andPERF, excluding intentionalPERF203cases. - Replaces manual list and dictionary construction with comprehensions and
dict.fromkeys(). - Removes redundant comprehensions.
Blocking findings:
- Critical: Remaining
PERF401violations exist incheck.pyandmcp.py. - Critical: Remaining
PERF403violations exist incloudsmith_cli/core/mcp/server.py.
Reviewed changes
Copilot reviewed 12 out of 12 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Summary |
|---|---|
pyproject.toml |
Updates Ruff rule configuration; critical lint violations remain. |
packaging/pyinstaller/entry.py |
Simplifies keyring failure collection. |
cloudsmith_cli/credential_helpers/docker/installer.py |
Refactors action collection. |
cloudsmith_cli/core/download.py |
Uses a filtering comprehension. |
cloudsmith_cli/core/api/vulnerabilities.py |
Simplifies table and count construction. |
cloudsmith_cli/core/api/packages.py |
Simplifies payload and default dictionary creation. |
cloudsmith_cli/cli/table.py |
Removes a redundant comprehension. |
cloudsmith_cli/cli/config.py |
Simplifies config path construction. |
cloudsmith_cli/cli/commands/repos.py |
Uses a table-row comprehension. |
cloudsmith_cli/cli/commands/list_.py |
Uses a package-row comprehension. |
cloudsmith_cli/cli/commands/download.py |
Uses an item comprehension. |
cloudsmith_cli/cli/commands/dependencies.py |
Uses a dependency-row comprehension. |
Suppressed comments (1)
cloudsmith_cli/cli/table.py:25
- This assignment is immediately overwritten by the initialization at line 42, so the new comprehension still calls
strandstrip_ansifor every row and discards the result. Removing only the outer no-op comprehension did not remove the dead work; delete this precomputation (and the similarly overwrittenplain_headersassignment above) instead.
plain_rows = [strip_ansi(str(v)) for v in rows]
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
cloudsmith-iduffy
force-pushed
the
lint/perf-lint-rules
branch
from
August 24, 2026 10:21
2de7450 to
15ffbe0
Compare
cloudsmith-iduffy
force-pushed
the
lint/perf-lint-rules
branch
from
August 24, 2026 13:15
15ffbe0 to
cde508d
Compare
cloudsmith-iduffy
force-pushed
the
lint/perf-lint-rules
branch
from
August 24, 2026 15:45
cde508d to
d6338b1
Compare
apoclyps
approved these changes
Aug 24, 2026
cloudsmith-iduffy
force-pushed
the
lint/perf-lint-rules
branch
from
August 24, 2026 17:58
d6338b1 to
e887dc9
Compare
cloudsmith-iduffy
force-pushed
the
lint/perf-lint-rules
branch
from
August 25, 2026 11:21
e887dc9 to
41988e0
Compare
cloudsmith-iduffy
force-pushed
the
lint/perf-lint-rules
branch
from
August 25, 2026 11:30
41988e0 to
c892e4f
Compare
cloudsmith-iduffy
force-pushed
the
lint/perf-lint-rules
branch
from
August 25, 2026 11:40
c892e4f to
fbbdb29
Compare
cloudsmith-iduffy
force-pushed
the
lint/perf-lint-rules
branch
2 times, most recently
from
August 25, 2026 12:08
9ff69bd to
81652d0
Compare
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 25, 2026 13:23
81652d0 to
25ae880
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