mirror of
https://github.com/google/brotli.git
synced 2026-07-08 17:56:58 +00:00
[PR #1392] [MERGED] Add ruff rule PERF for performance #2001
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
📋 Pull Request Information
Original PR: https://github.com/google/brotli/pull/1392
Author: @cclauss
Created: 11/20/2025
Status: ✅ Merged
Merged: 11/24/2025
Merged by: @copybara-service[bot]
Base:
master← Head:comprehensions📝 Commits (3)
7ff6d1dAdd ruff rule PERF for performance688d661Merge branch 'master' into comprehensions5db7acaMerge branch 'master' into comprehensions📊 Changes
4 files changed (+18 additions, -26 deletions)
View changed files
📝
.github/workflows/lint.yml(+1 -1)📝
scripts/dictionary/step-02-rfc-to-bin.py(+3 -5)📝
scripts/dictionary/step-04-generate-java-literals.py(+10 -11)📝
setup.py(+4 -9)📄 Description
%
ruff check --extend-select=C4,C90,PERF,RET,SIM,W%
ruff rule PERF401manual-list-comprehension (PERF401)
Derived from the Perflint linter.
Fix is sometimes available.
What it does
Checks for
forloops that can be replaced by a list comprehension.Why is this bad?
When creating a transformed list from an existing list using a for-loop,
prefer a list comprehension. List comprehensions are more readable and
more performant.
Using the below as an example, the list comprehension is ~10% faster on
Python 3.11, and ~25% faster on Python 3.10.
Note that, as with all
perflintrules, this is only intended as amicro-optimization, and will have a negligible impact on performance in
most cases.
Example
Use instead:
If you're appending to an existing list, use the
extendmethod instead:🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.