Skip to content

Commit 6372976

Browse files
committed
Remove unnecessary coerce to float
In Python 3, the division operator is floating point division. No longer need to coerce integers to floating point numbers before division.
1 parent a0a9b76 commit 6372976

11 files changed

Lines changed: 22 additions & 23 deletions

Tests/helper.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,6 @@ def assert_image_equal_tofile(self, a, filename, msg=None, mode=None):
124124
self.assert_image_equal(a, img, msg)
125125

126126
def assert_image_similar(self, a, b, epsilon, msg=None):
127-
epsilon = float(epsilon)
128127
self.assertEqual(
129128
a.mode, b.mode, msg or "got mode {!r}, expected {!r}".format(a.mode, b.mode)
130129
)
@@ -139,7 +138,7 @@ def assert_image_similar(self, a, b, epsilon, msg=None):
139138
chdiff = ImageMath.eval("abs(a - b)", a=ach, b=bch).convert("L")
140139
diff += sum(i * num for i, num in enumerate(chdiff.histogram()))
141140

142-
ave_diff = float(diff) / (a.size[0] * a.size[1])
141+
ave_diff = diff / (a.size[0] * a.size[1])
143142
try:
144143
self.assertGreaterEqual(
145144
epsilon,

Tests/test_color_lut.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,11 @@ def generate_identity_table(self, channels, size):
2020

2121
table = [
2222
[
23-
r / float(size1D - 1) if size1D != 1 else 0,
24-
g / float(size2D - 1) if size2D != 1 else 0,
25-
b / float(size3D - 1) if size3D != 1 else 0,
26-
r / float(size1D - 1) if size1D != 1 else 0,
27-
g / float(size2D - 1) if size2D != 1 else 0,
23+
r / (size1D - 1) if size1D != 1 else 0,
24+
g / (size2D - 1) if size2D != 1 else 0,
25+
b / (size3D - 1) if size3D != 1 else 0,
26+
r / (size1D - 1) if size1D != 1 else 0,
27+
g / (size2D - 1) if size2D != 1 else 0,
2828
][:channels]
2929
for b in range(size3D)
3030
for g in range(size2D)

Tests/test_format_hsv.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@
88

99
class TestFormatHSV(PillowTestCase):
1010
def int_to_float(self, i):
11-
return float(i) / 255.0
11+
return i / 255
1212

1313
def str_to_float(self, i):
14-
return float(ord(i)) / 255.0
14+
return ord(i) / 255
1515

1616
def tuple_to_ints(self, tp):
1717
x, y, z = tp

Tests/test_image_reduce.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ def assert_compare_images(self, a, b, max_average_diff, max_diff=255):
164164
ch_diff = ImageMath.eval("convert(abs(a - b), 'L')", a=ach, b=bch)
165165
ch_hist = ch_diff.histogram()
166166

167-
average_diff = sum(i * num for i, num in enumerate(ch_hist)) / float(
167+
average_diff = sum(i * num for i, num in enumerate(ch_hist)) / (
168168
a.size[0] * a.size[1]
169169
)
170170
self.assertGreaterEqual(

Tests/test_imagecms.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -499,8 +499,8 @@ def create_test_image():
499499
# paste pattern with varying offsets to avoid correlation
500500
# potentially hiding some bugs (like channels getting mixed).
501501
paste_offset = (
502-
int(band_ndx / float(len(bands)) * channel_pattern.size[0]),
503-
int(band_ndx / float(len(bands) * 2) * channel_pattern.size[1]),
502+
int(band_ndx / len(bands) * channel_pattern.size[0]),
503+
int(band_ndx / (len(bands) * 2) * channel_pattern.size[1]),
504504
)
505505
channel_data = Image.new(channel_type, channel_pattern.size)
506506
for delta in nine_grid_deltas:

src/PIL/EpsImagePlugin.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,8 @@ def Ghostscript(tile, size, fp, scale=1):
7575
size = (size[0] * scale, size[1] * scale)
7676
# resolution is dependent on bbox and size
7777
res = (
78-
float((72.0 * size[0]) / (bbox[2] - bbox[0])),
79-
float((72.0 * size[1]) / (bbox[3] - bbox[1])),
78+
72.0 * size[0] / (bbox[2] - bbox[0]),
79+
72.0 * size[1] / (bbox[3] - bbox[1]),
8080
)
8181

8282
out_fd, outfile = tempfile.mkstemp()

src/PIL/GimpGradientFile.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ def getpalette(self, entries=256):
7373

7474
for i in range(entries):
7575

76-
x = i / float(entries - 1)
76+
x = i / (entries - 1)
7777

7878
while x1 < x:
7979
ix += 1

src/PIL/Image.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2357,8 +2357,8 @@ def __transformer(self, box, image, method, data, resample=NEAREST, fill=1):
23572357
elif method == EXTENT:
23582358
# convert extent to an affine transform
23592359
x0, y0, x1, y1 = data
2360-
xs = float(x1 - x0) / w
2361-
ys = float(y1 - y0) / h
2360+
xs = (x1 - x0) / w
2361+
ys = (y1 - y0) / h
23622362
method = AFFINE
23632363
data = (xs, 0, x0, 0, ys, y0)
23642364

src/PIL/ImageOps.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,7 @@ def pad(image, size, method=Image.BICUBIC, color=None, centering=(0.5, 0.5)):
243243
"""
244244

245245
im_ratio = image.width / image.height
246-
dest_ratio = float(size[0]) / size[1]
246+
dest_ratio = size[0] / size[1]
247247

248248
if im_ratio == dest_ratio:
249249
out = image.resize(size, resample=method)
@@ -420,10 +420,10 @@ def fit(image, size, method=Image.BICUBIC, bleed=0.0, centering=(0.5, 0.5)):
420420
)
421421

422422
# calculate the aspect ratio of the live_size
423-
live_size_ratio = float(live_size[0]) / live_size[1]
423+
live_size_ratio = live_size[0] / live_size[1]
424424

425425
# calculate the aspect ratio of the output image
426-
output_ratio = float(size[0]) / size[1]
426+
output_ratio = size[0] / size[1]
427427

428428
# figure out if the sides or top/bottom will be cropped off
429429
if live_size_ratio == output_ratio:

src/PIL/JpegImagePlugin.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -437,7 +437,7 @@ def draft(self, mode, size):
437437
self.tile = [(d, e, o, a)]
438438
self.decoderconfig = (scale, 0)
439439

440-
box = (0, 0, original_size[0] / float(scale), original_size[1] / float(scale))
440+
box = (0, 0, original_size[0] / scale, original_size[1] / scale)
441441
return (self.mode, box)
442442

443443
def load_djpeg(self):

0 commit comments

Comments
 (0)