mirror of
https://github.com/python-pillow/Pillow.git
synced 2024-11-14 05:36:48 +03:00
Merge pull request #7524 from cclauss/ruff-rules-C4-PERF102-PIE810-PLR
This commit is contained in:
commit
76446ee450
|
@ -67,7 +67,7 @@ def test_quantize_no_dither():
|
||||||
|
|
||||||
def test_quantize_no_dither2():
|
def test_quantize_no_dither2():
|
||||||
im = Image.new("RGB", (9, 1))
|
im = Image.new("RGB", (9, 1))
|
||||||
im.putdata(list((p,) * 3 for p in range(0, 36, 4)))
|
im.putdata([(p,) * 3 for p in range(0, 36, 4)])
|
||||||
|
|
||||||
palette = Image.new("P", (1, 1))
|
palette = Image.new("P", (1, 1))
|
||||||
data = (0, 0, 0, 32, 32, 32)
|
data = (0, 0, 0, 32, 32, 32)
|
||||||
|
|
|
@ -96,6 +96,7 @@ test-extras = "tests"
|
||||||
[tool.ruff]
|
[tool.ruff]
|
||||||
line-length = 88
|
line-length = 88
|
||||||
select = [
|
select = [
|
||||||
|
"C4", # flake8-comprehensions
|
||||||
"E", # pycodestyle errors
|
"E", # pycodestyle errors
|
||||||
"EM", # flake8-errmsg
|
"EM", # flake8-errmsg
|
||||||
"F", # pyflakes errors
|
"F", # pyflakes errors
|
||||||
|
|
22
setup.py
22
setup.py
|
@ -440,17 +440,17 @@ class pil_build_ext(build_ext):
|
||||||
|
|
||||||
#
|
#
|
||||||
# add configured kits
|
# add configured kits
|
||||||
for root_name, lib_name in dict(
|
for root_name, lib_name in {
|
||||||
JPEG_ROOT="libjpeg",
|
"JPEG_ROOT": "libjpeg",
|
||||||
JPEG2K_ROOT="libopenjp2",
|
"JPEG2K_ROOT": "libopenjp2",
|
||||||
TIFF_ROOT=("libtiff-5", "libtiff-4"),
|
"TIFF_ROOT": ("libtiff-5", "libtiff-4"),
|
||||||
ZLIB_ROOT="zlib",
|
"ZLIB_ROOT": "zlib",
|
||||||
FREETYPE_ROOT="freetype2",
|
"FREETYPE_ROOT": "freetype2",
|
||||||
HARFBUZZ_ROOT="harfbuzz",
|
"HARFBUZZ_ROOT": "harfbuzz",
|
||||||
FRIBIDI_ROOT="fribidi",
|
"FRIBIDI_ROOT": "fribidi",
|
||||||
LCMS_ROOT="lcms2",
|
"LCMS_ROOT": "lcms2",
|
||||||
IMAGEQUANT_ROOT="libimagequant",
|
"IMAGEQUANT_ROOT": "libimagequant",
|
||||||
).items():
|
}.items():
|
||||||
root = globals()[root_name]
|
root = globals()[root_name]
|
||||||
|
|
||||||
if root is None and root_name in os.environ:
|
if root is None and root_name in os.environ:
|
||||||
|
|
|
@ -396,7 +396,7 @@ def _save(im, fp, filename, bitmap_header=True):
|
||||||
dpi = info.get("dpi", (96, 96))
|
dpi = info.get("dpi", (96, 96))
|
||||||
|
|
||||||
# 1 meter == 39.3701 inches
|
# 1 meter == 39.3701 inches
|
||||||
ppm = tuple(map(lambda x: int(x * 39.3701 + 0.5), dpi))
|
ppm = tuple(int(x * 39.3701 + 0.5) for x in dpi)
|
||||||
|
|
||||||
stride = ((im.size[0] * bits + 7) // 8 + 3) & (~3)
|
stride = ((im.size[0] * bits + 7) // 8 + 3) & (~3)
|
||||||
header = 40 # or 64 for OS/2 version 2
|
header = 40 # or 64 for OS/2 version 2
|
||||||
|
|
|
@ -64,8 +64,6 @@ class CurImageFile(BmpImagePlugin.BmpImageFile):
|
||||||
d, e, o, a = self.tile[0]
|
d, e, o, a = self.tile[0]
|
||||||
self.tile[0] = d, (0, 0) + self.size, o, a
|
self.tile[0] = d, (0, 0) + self.size, o, a
|
||||||
|
|
||||||
return
|
|
||||||
|
|
||||||
|
|
||||||
#
|
#
|
||||||
# --------------------------------------------------------------------
|
# --------------------------------------------------------------------
|
||||||
|
|
|
@ -40,7 +40,7 @@ from enum import IntEnum
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
|
||||||
try:
|
try:
|
||||||
import defusedxml.ElementTree as ElementTree
|
from defusedxml import ElementTree
|
||||||
except ImportError:
|
except ImportError:
|
||||||
ElementTree = None
|
ElementTree = None
|
||||||
|
|
||||||
|
@ -1160,7 +1160,7 @@ class Image:
|
||||||
if palette.mode != "P":
|
if palette.mode != "P":
|
||||||
msg = "bad mode for palette image"
|
msg = "bad mode for palette image"
|
||||||
raise ValueError(msg)
|
raise ValueError(msg)
|
||||||
if self.mode != "RGB" and self.mode != "L":
|
if self.mode not in {"RGB", "L"}:
|
||||||
msg = "only RGB or L mode images can be quantized to a palette"
|
msg = "only RGB or L mode images can be quantized to a palette"
|
||||||
raise ValueError(msg)
|
raise ValueError(msg)
|
||||||
im = self.im.convert("P", dither, palette.im)
|
im = self.im.convert("P", dither, palette.im)
|
||||||
|
|
|
@ -921,7 +921,7 @@ def floodfill(image, xy, value, border=None, thresh=0):
|
||||||
if border is None:
|
if border is None:
|
||||||
fill = _color_diff(p, background) <= thresh
|
fill = _color_diff(p, background) <= thresh
|
||||||
else:
|
else:
|
||||||
fill = p != value and p != border
|
fill = p not in (value, border)
|
||||||
if fill:
|
if fill:
|
||||||
pixel[s, t] = value
|
pixel[s, t] = value
|
||||||
new_edge.add((s, t))
|
new_edge.add((s, t))
|
||||||
|
|
|
@ -334,10 +334,7 @@ def _save(im, fp, filename):
|
||||||
if quality_layers is not None and not (
|
if quality_layers is not None and not (
|
||||||
isinstance(quality_layers, (list, tuple))
|
isinstance(quality_layers, (list, tuple))
|
||||||
and all(
|
and all(
|
||||||
[
|
isinstance(quality_layer, (int, float)) for quality_layer in quality_layers
|
||||||
isinstance(quality_layer, (int, float))
|
|
||||||
for quality_layer in quality_layers
|
|
||||||
]
|
|
||||||
)
|
)
|
||||||
):
|
):
|
||||||
msg = "quality_layers must be a sequence of numbers"
|
msg = "quality_layers must be a sequence of numbers"
|
||||||
|
|
|
@ -397,7 +397,7 @@ class JpegImageFile(ImageFile.ImageFile):
|
||||||
# self.__offset = self.fp.tell()
|
# self.__offset = self.fp.tell()
|
||||||
break
|
break
|
||||||
s = self.fp.read(1)
|
s = self.fp.read(1)
|
||||||
elif i == 0 or i == 0xFFFF:
|
elif i in {0, 0xFFFF}:
|
||||||
# padded marker or junk; move on
|
# padded marker or junk; move on
|
||||||
s = b"\xff"
|
s = b"\xff"
|
||||||
elif i == 0xFF00: # Skip extraneous data (escaped 0xFF)
|
elif i == 0xFF00: # Skip extraneous data (escaped 0xFF)
|
||||||
|
|
|
@ -123,7 +123,7 @@ class SgiImageFile(ImageFile.ImageFile):
|
||||||
|
|
||||||
|
|
||||||
def _save(im, fp, filename):
|
def _save(im, fp, filename):
|
||||||
if im.mode != "RGB" and im.mode != "RGBA" and im.mode != "L":
|
if im.mode not in {"RGB", "RGBA", "L"}:
|
||||||
msg = "Unsupported SGI image mode"
|
msg = "Unsupported SGI image mode"
|
||||||
raise ValueError(msg)
|
raise ValueError(msg)
|
||||||
|
|
||||||
|
@ -155,7 +155,7 @@ def _save(im, fp, filename):
|
||||||
# Z Dimension: Number of channels
|
# Z Dimension: Number of channels
|
||||||
z = len(im.mode)
|
z = len(im.mode)
|
||||||
|
|
||||||
if dim == 1 or dim == 2:
|
if dim in {1, 2}:
|
||||||
z = 1
|
z = 1
|
||||||
|
|
||||||
# assert we've got the right number of bands.
|
# assert we've got the right number of bands.
|
||||||
|
|
|
@ -427,7 +427,7 @@ def _populate():
|
||||||
|
|
||||||
TAGS_V2[k] = TagInfo(k, *v)
|
TAGS_V2[k] = TagInfo(k, *v)
|
||||||
|
|
||||||
for group, tags in TAGS_V2_GROUPS.items():
|
for tags in TAGS_V2_GROUPS.values():
|
||||||
for k, v in tags.items():
|
for k, v in tags.items():
|
||||||
tags[k] = TagInfo(k, *v)
|
tags[k] = TagInfo(k, *v)
|
||||||
|
|
||||||
|
|
|
@ -482,7 +482,7 @@ def extract_dep(url: str, filename: str) -> None:
|
||||||
msg = "Attempted Path Traversal in Zip File"
|
msg = "Attempted Path Traversal in Zip File"
|
||||||
raise RuntimeError(msg)
|
raise RuntimeError(msg)
|
||||||
zf.extractall(sources_dir)
|
zf.extractall(sources_dir)
|
||||||
elif filename.endswith(".tar.gz") or filename.endswith(".tgz"):
|
elif filename.endswith((".tar.gz", ".tgz")):
|
||||||
with tarfile.open(file, "r:gz") as tgz:
|
with tarfile.open(file, "r:gz") as tgz:
|
||||||
for member in tgz.getnames():
|
for member in tgz.getnames():
|
||||||
member_abspath = os.path.abspath(os.path.join(sources_dir, member))
|
member_abspath = os.path.abspath(os.path.join(sources_dir, member))
|
||||||
|
|
Loading…
Reference in New Issue
Block a user