Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Use list comprehensions to create transformed lists#7597

Merged
radarhere merged 4 commits into
python-pillow:mainfrom
hugovk:comprehensions
Dec 5, 2023
Merged

Use list comprehensions to create transformed lists#7597
radarhere merged 4 commits into
python-pillow:mainfrom
hugovk:comprehensions

Conversation

@hugovk

@hugovk hugovk commented Dec 3, 2023

Copy link
Copy Markdown
Member

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

Comment thread src/PIL/ImageOps.py Outdated
Comment thread src/PIL/PcfFontFile.py Outdated
Comment thread src/PIL/SpiderImagePlugin.py Outdated
Comment thread src/PIL/ImageStat.py Outdated
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
Copy Markdown
Member

Choose a reason for hiding this comment

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

Comment thread src/PIL/ImageCms.py
Comment thread src/PIL/ImageOps.py Outdated
hugovk and others added 2 commits December 4, 2023 16:34
Comment thread src/PIL/ImagePalette.py Outdated
@radarhere radarhere merged commit 0a66b98 into python-pillow:main Dec 5, 2023
@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