diff --git a/Tests/test_color_lut.py b/Tests/test_color_lut.py index 120ff777e..d2e2d5156 100644 --- a/Tests/test_color_lut.py +++ b/Tests/test_color_lut.py @@ -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 diff --git a/Tests/test_imagesequence.py b/Tests/test_imagesequence.py index 7cf237b46..d79e8e525 100644 --- a/Tests/test_imagesequence.py +++ b/Tests/test_imagesequence.py @@ -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 diff --git a/src/PIL/GribStubImagePlugin.py b/src/PIL/GribStubImagePlugin.py index cc9bc2639..4575f8237 100644 --- a/src/PIL/GribStubImagePlugin.py +++ b/src/PIL/GribStubImagePlugin.py @@ -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): diff --git a/src/PIL/ImImagePlugin.py b/src/PIL/ImImagePlugin.py index f7e690b35..5563da4f5 100644 --- a/src/PIL/ImImagePlugin.py +++ b/src/PIL/ImImagePlugin.py @@ -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") diff --git a/src/PIL/Image.py b/src/PIL/Image.py index ca7f8308e..853ed15d5 100644 --- a/src/PIL/Image.py +++ b/src/PIL/Image.py @@ -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] diff --git a/src/PIL/ImageColor.py b/src/PIL/ImageColor.py index 958635bf9..3cf9ddafc 100644 --- a/src/PIL/ImageColor.py +++ b/src/PIL/ImageColor.py @@ -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 diff --git a/src/PIL/ImageMorph.py b/src/PIL/ImageMorph.py index fe0083754..1e22c36a8 100644 --- a/src/PIL/ImageMorph.py +++ b/src/PIL/ImageMorph.py @@ -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) diff --git a/src/PIL/JpegImagePlugin.py b/src/PIL/JpegImagePlugin.py index aae2a4591..92417eacd 100644 --- a/src/PIL/JpegImagePlugin.py +++ b/src/PIL/JpegImagePlugin.py @@ -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" ## diff --git a/src/PIL/PaletteFile.py b/src/PIL/PaletteFile.py index 6ccaa1f53..ee9dca860 100644 --- a/src/PIL/PaletteFile.py +++ b/src/PIL/PaletteFile.py @@ -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") diff --git a/src/PIL/XpmImagePlugin.py b/src/PIL/XpmImagePlugin.py index 19c50cafc..aaed2039d 100644 --- a/src/PIL/XpmImagePlugin.py +++ b/src/PIL/XpmImagePlugin.py @@ -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] = (