Skip to content

Commit 981684b

Browse files
committed
Revert unrolling of ImageSlide.read_region()
Keep the type checker happy by asserting the correct tuple lengths rather than unrolling generator expressions. Signed-off-by: Benjamin Gilbert <[email protected]>
1 parent 0d675d6 commit 981684b

File tree

1 file changed

+4
-9
lines changed

1 file changed

+4
-9
lines changed

openslide/__init__.py

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -466,15 +466,10 @@ def read_region(
466466
]: # "< 0" not a typo
467467
# Crop size is greater than zero in both dimensions.
468468
# PIL thinks the bottom right is the first *excluded* pixel
469-
crop = self._image.crop(
470-
(
471-
image_topleft[0],
472-
image_topleft[1],
473-
image_bottomright[0] + 1,
474-
image_bottomright[1] + 1,
475-
)
476-
)
477-
tile_offset = image_topleft[0] - location[0], image_topleft[1] - location[1]
469+
crop_box = tuple(image_topleft + [d + 1 for d in image_bottomright])
470+
tile_offset = tuple(il - l for il, l in zip(image_topleft, location))
471+
assert len(crop_box) == 4 and len(tile_offset) == 2
472+
crop = self._image.crop(crop_box)
478473
tile.paste(crop, tile_offset)
479474
if self._profile is not None:
480475
tile.info['icc_profile'] = self._profile

0 commit comments

Comments
 (0)