Merge pull request #88 from radarhere/cleanup

This commit is contained in:
Hugo van Kemenade 2022-04-25 22:06:52 +03:00 committed by GitHub
commit 64880ab8d5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
10 changed files with 19 additions and 19 deletions

View File

@ -567,7 +567,7 @@ class TestTransformColorLut3D:
assert tuple(lut.size) == tuple(source.size)
assert len(lut.table) == len(source.table)
assert lut.table != source.table
assert lut.table[0:10] == [0.0, 0.0, 0.0, 0.25, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0]
assert lut.table[:10] == [0.0, 0.0, 0.0, 0.25, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0]
def test_3_to_4_channels(self):
source = ImageFilter.Color3DLUT.generate((6, 5, 4), lambda r, g, b: (r, g, b))
@ -576,7 +576,7 @@ class TestTransformColorLut3D:
assert len(lut.table) != len(source.table)
assert lut.table != source.table
# fmt: off
assert lut.table[0:16] == [
assert lut.table[:16] == [
0.0, 0.0, 0.0, 1, 0.2**2, 0.0, 0.0, 1,
0.4**2, 0.0, 0.0, 1, 0.6**2, 0.0, 0.0, 1]
# fmt: on
@ -592,7 +592,7 @@ class TestTransformColorLut3D:
assert len(lut.table) != len(source.table)
assert lut.table != source.table
# fmt: off
assert lut.table[0:18] == [
assert lut.table[:18] == [
1.0, 1.0, 1.0, 0.75, 1.0, 1.0, 0.0, 1.0, 1.0,
1.0, 0.96, 1.0, 0.75, 0.96, 1.0, 0.0, 0.96, 1.0]
# fmt: on
@ -606,7 +606,7 @@ class TestTransformColorLut3D:
assert len(lut.table) == len(source.table)
assert lut.table != source.table
# fmt: off
assert lut.table[0:16] == [
assert lut.table[:16] == [
0.0, 0.0, 0.0, 0.5, 0.2**2, 0.0, 0.0, 0.5,
0.4**2, 0.0, 0.0, 0.5, 0.6**2, 0.0, 0.0, 0.5]
# fmt: on
@ -622,7 +622,7 @@ class TestTransformColorLut3D:
assert len(lut.table) == len(source.table)
assert lut.table != source.table
# fmt: off
assert lut.table[0:18] == [
assert lut.table[:18] == [
0.0, 0.0, 0.0, 0.16, 0.0, 0.0, 0.24, 0.0, 0.0,
0.24, 0.0, 0.0, 0.8 - (0.8**2), 0, 0, 0, 0, 0]
# fmt: on
@ -639,7 +639,7 @@ class TestTransformColorLut3D:
assert len(lut.table) == len(source.table)
assert lut.table != source.table
# fmt: off
assert lut.table[0:16] == [
assert lut.table[:16] == [
0.0, 0.0, 0.0, 0.5, 0.25, 0.0, 0.0, 0.5,
0.0, 0.0, 0.0, 0.5, 0.0, 0.16, 0.0, 0.5]
# fmt: on

View File

@ -77,9 +77,9 @@ def test_consecutive():
def test_palette_mmap():
# Using mmap in ImageFile can require to reload the palette.
with Image.open("Tests/images/multipage-mmap.tiff") as im:
color1 = im.getpalette()[0:3]
color1 = im.getpalette()[:3]
im.seek(0)
color2 = im.getpalette()[0:3]
color2 = im.getpalette()[:3]
assert color1 == color2

View File

@ -29,7 +29,7 @@ def register_handler(handler):
def _accept(prefix):
return prefix[0:4] == b"GRIB" and prefix[7] == 1
return prefix[:4] == b"GRIB" and prefix[7] == 1
class GribStubImageFile(ImageFile.StubImageFile):

View File

@ -210,7 +210,7 @@ class ImImageFile(ImageFile.ImageFile):
self.mode = self.info[MODE]
# Skip forward to start of image data
while s and s[0:1] != b"\x1A":
while s and s[:1] != b"\x1A":
s = self.fp.read(1)
if not s:
raise SyntaxError("File truncated")

View File

@ -2582,7 +2582,7 @@ class Image:
h = box[3] - box[1]
if method == Transform.AFFINE:
data = data[0:6]
data = data[:6]
elif method == Transform.EXTENT:
# convert extent to an affine transform
@ -2593,12 +2593,12 @@ class Image:
data = (xs, 0, x0, 0, ys, y0)
elif method == Transform.PERSPECTIVE:
data = data[0:8]
data = data[:8]
elif method == Transform.QUAD:
# quadrilateral warp. data specifies the four corners
# given as NW, SW, SE, and NE.
nw = data[0:2]
nw = data[:2]
sw = data[2:4]
se = data[4:6]
ne = data[6:8]

View File

@ -133,7 +133,7 @@ def getcolor(color, mode):
# same as getrgb, but converts the result to the given mode
color, alpha = getrgb(color), 255
if len(color) == 4:
color, alpha = color[0:3], color[3]
color, alpha = color[:3], color[3]
if Image.getmodebase(mode) == "L":
r, g, b = color

View File

@ -119,13 +119,13 @@ class LutBuilder:
# mirror
if "M" in options:
n = len(patterns)
for pattern, res in patterns[0:n]:
for pattern, res in patterns[:n]:
patterns.append((self._string_permute(pattern, MIRROR_MATRIX), res))
# negate
if "N" in options:
n = len(patterns)
for pattern, res in patterns[0:n]:
for pattern, res in patterns[:n]:
# Swap 0 and 1
pattern = pattern.replace("0", "Z").replace("1", "0").replace("Z", "1")
res = 1 - int(res)

View File

@ -330,7 +330,7 @@ MARKER = {
def _accept(prefix):
# Magic number was taken from https://en.wikipedia.org/wiki/JPEG
return prefix[0:3] == b"\xFF\xD8\xFF"
return prefix[:3] == b"\xFF\xD8\xFF"
##

View File

@ -31,7 +31,7 @@ class PaletteFile:
if not s:
break
if s[0:1] == b"#":
if s[:1] == b"#":
continue
if len(s) > 100:
raise SyntaxError("bad palette file")

View File

@ -83,7 +83,7 @@ class XpmImageFile(ImageFile.ImageFile):
rgb = s[i + 1]
if rgb == b"None":
self.info["transparency"] = c
elif rgb[0:1] == b"#":
elif rgb[:1] == b"#":
# FIXME: handle colour names (see ImagePalette.py)
rgb = int(rgb[1:], 16)
palette[c] = (