Skip to content

Commit

Permalink
Remove redundant bytearray
Browse files Browse the repository at this point in the history
  • Loading branch information
hugovk committed Oct 7, 2019
1 parent 865b17d commit 4382413
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 11 deletions.
14 changes: 6 additions & 8 deletions Tests/test_file_gif.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,7 @@ def test_optimize_correctness(self):
def check(colors, size, expected_palette_length):
# make an image with empty colors in the start of the palette range
im = Image.frombytes(
"P",
(colors, colors),
bytes(bytearray(range(256 - colors, 256)) * colors),
"P", (colors, colors), bytes(range(256 - colors, 256)) * colors
)
im = im.resize((size, size))
outfile = BytesIO()
Expand Down Expand Up @@ -103,7 +101,7 @@ def check(colors, size, expected_palette_length):
check(256, 511, 256)

def test_optimize_full_l(self):
im = Image.frombytes("L", (16, 16), bytes(bytearray(range(256))))
im = Image.frombytes("L", (16, 16), bytes(range(256)))
test_file = BytesIO()
im.save(test_file, "GIF", optimize=True)
self.assertEqual(im.mode, "L")
Expand Down Expand Up @@ -632,7 +630,7 @@ def test_transparent_optimize(self):
# that's > 128 items where the transparent color is actually
# the top palette entry to trigger the bug.

data = bytes(bytearray(range(1, 254)))
data = bytes(range(1, 254))
palette = ImagePalette.ImagePalette("RGB", list(range(256)) * 3)

im = Image.new("L", (253, 1))
Expand Down Expand Up @@ -680,7 +678,7 @@ def test_palette_save_L(self):

im = hopper("P")
im_l = Image.frombytes("L", im.size, im.tobytes())
palette = bytes(bytearray(im.getpalette()))
palette = bytes(im.getpalette())

out = self.tempfile("temp.gif")
im_l.save(out, palette=palette)
Expand All @@ -695,7 +693,7 @@ def test_palette_save_P(self):
# Forcing a non-straight grayscale palette.

im = hopper("P")
palette = bytes(bytearray([255 - i // 3 for i in range(768)]))
palette = bytes([255 - i // 3 for i in range(768)])

out = self.tempfile("temp.gif")
im.save(out, palette=palette)
Expand Down Expand Up @@ -736,7 +734,7 @@ def test_getdata(self):
im.putpalette(ImagePalette.ImagePalette("RGB"))
im.info = {"background": 0}

passed_palette = bytes(bytearray([255 - i // 3 for i in range(768)]))
passed_palette = bytes([255 - i // 3 for i in range(768)])

GifImagePlugin._FORCE_OPTIMIZE = True
try:
Expand Down
4 changes: 2 additions & 2 deletions Tests/test_lib_pack.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ def assert_pack(self, mode, rawmode, data, *pixels):

if isinstance(data, int):
data_len = data * len(pixels)
data = bytes(bytearray(range(1, data_len + 1)))
data = bytes(range(1, data_len + 1))

self.assertEqual(data, im.tobytes("raw", rawmode))

Expand Down Expand Up @@ -226,7 +226,7 @@ def assert_unpack(self, mode, rawmode, data, *pixels):
"""
if isinstance(data, int):
data_len = data * len(pixels)
data = bytes(bytearray(range(1, data_len + 1)))
data = bytes(range(1, data_len + 1))

im = Image.frombytes(mode, (len(pixels), 1), data, "raw", rawmode, 0, 1)

Expand Down
2 changes: 1 addition & 1 deletion src/PIL/TiffImagePlugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -1742,7 +1742,7 @@ def goToEnd(self):
# pad to 16 byte boundary
padBytes = 16 - pos % 16
if 0 < padBytes < 16:
self.f.write(bytes(bytearray(padBytes)))
self.f.write(bytes(padBytes))
self.offsetOfNewPage = self.f.tell()

def setEndian(self, endian):
Expand Down

0 comments on commit 4382413

Please sign in to comment.