Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use list comprehensions to create transformed lists #7597

Merged
merged 4 commits into from
Dec 5, 2023

Conversation

hugovk
Copy link
Member

@hugovk hugovk commented Dec 3, 2023

Changes proposed in this pull request:

  • Replace some for loops with list comprehensions
  • Identified with ruff . --select PERF401: "PERF401 Use a list comprehension to create a transformed list"
  • https://docs.astral.sh/ruff/rules/manual-list-comprehension/
  • It finds some that can't be easily replaced, so I didn't add this rule to pyproject.toml

src/PIL/ImageOps.py Outdated Show resolved Hide resolved
src/PIL/PcfFontFile.py Outdated Show resolved Hide resolved
src/PIL/SpiderImagePlugin.py Outdated Show resolved Hide resolved
v.append(functools.reduce(operator.add, self.h[i : i + 256]))
return v
return [
functools.reduce(operator.add, self.h[i : i + 256])
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

src/PIL/ImageCms.py Show resolved Hide resolved
src/PIL/ImageOps.py Outdated Show resolved Hide resolved
hugovk and others added 2 commits December 4, 2023 16:34
Co-authored-by: Andrew Murray <3112309+radarhere@users.noreply.github.com>
Co-authored-by: Alexander Karpinsky <homm86@gmail.com>
src/PIL/ImagePalette.py Outdated Show resolved Hide resolved
Co-authored-by: Andrew Murray <3112309+radarhere@users.noreply.github.com>
@radarhere radarhere merged commit 0a66b98 into python-pillow:main Dec 5, 2023
55 of 56 checks passed
@hugovk hugovk deleted the comprehensions branch December 5, 2023 10:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants