Skip to content

Commit ed5cd18

Browse files
committed
Always return fresh not-yet-loaded image for hopper(None)
1 parent 199bff3 commit ed5cd18

1 file changed

Lines changed: 8 additions & 6 deletions

File tree

Tests/helper.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -255,20 +255,22 @@ def hopper(mode: str | None = None) -> Image.Image:
255255
# Use caching to reduce reading from disk, but return a copy
256256
# so that the cached image isn't modified by the tests
257257
# (for fast, isolated, repeatable tests).
258-
return _cached_hopper(mode).copy()
259-
260258

261-
@lru_cache(maxsize=None)
262-
def _cached_hopper(mode: str | None = None) -> Image.Image:
263259
if mode is None:
264260
# Always return fresh not-yet-loaded version of image.
265261
# Operations on not-yet-loaded images is separate class of errors
266262
# what we should catch.
267263
return Image.open("Tests/images/hopper.ppm")
264+
265+
return _cached_hopper(mode).copy()
266+
267+
268+
@lru_cache(maxsize=None)
269+
def _cached_hopper(mode: str | None = None) -> Image.Image:
268270
if mode == "F":
269-
im = _cached_hopper("L").convert(mode)
271+
im = hopper("L").convert(mode)
270272
else:
271-
im = _cached_hopper().convert(mode)
273+
im = hopper().convert(mode)
272274
return im
273275

274276

0 commit comments

Comments
 (0)