Skip to content

Commit 9ae8cb8

Browse files
authored
Merge pull request #8657 from cdce8p/overload-exif_transpose
2 parents 48712f2 + d12e78b commit 9ae8cb8

File tree

3 files changed

+11
-8
lines changed

3 files changed

+11
-8
lines changed

Tests/test_file_jpeg.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -353,7 +353,6 @@ def test_empty_exif_gps(self) -> None:
353353
assert exif.get_ifd(0x8825) == {}
354354

355355
transposed = ImageOps.exif_transpose(im)
356-
assert transposed is not None
357356
exif = transposed.getexif()
358357
assert exif.get_ifd(0x8825) == {}
359358

Tests/test_imageops.py

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -405,7 +405,6 @@ def check(orientation_im: Image.Image) -> None:
405405
else:
406406
original_exif = im.info["exif"]
407407
transposed_im = ImageOps.exif_transpose(im)
408-
assert transposed_im is not None
409408
assert_image_similar(base_im, transposed_im, 17)
410409
if orientation_im is base_im:
411410
assert "exif" not in im.info
@@ -417,7 +416,6 @@ def check(orientation_im: Image.Image) -> None:
417416

418417
# Repeat the operation to test that it does not keep transposing
419418
transposed_im2 = ImageOps.exif_transpose(transposed_im)
420-
assert transposed_im2 is not None
421419
assert_image_equal(transposed_im2, transposed_im)
422420

423421
check(base_im)
@@ -433,7 +431,6 @@ def check(orientation_im: Image.Image) -> None:
433431
assert im.getexif()[0x0112] == 3
434432

435433
transposed_im = ImageOps.exif_transpose(im)
436-
assert transposed_im is not None
437434
assert 0x0112 not in transposed_im.getexif()
438435

439436
transposed_im._reload_exif()
@@ -446,14 +443,12 @@ def check(orientation_im: Image.Image) -> None:
446443
assert im.getexif()[0x0112] == 3
447444

448445
transposed_im = ImageOps.exif_transpose(im)
449-
assert transposed_im is not None
450446
assert 0x0112 not in transposed_im.getexif()
451447

452448
# Orientation set directly on Image.Exif
453449
im = hopper()
454450
im.getexif()[0x0112] = 3
455451
transposed_im = ImageOps.exif_transpose(im)
456-
assert transposed_im is not None
457452
assert 0x0112 not in transposed_im.getexif()
458453

459454

@@ -464,7 +459,6 @@ def test_exif_transpose_xml_without_xmp() -> None:
464459

465460
del im.info["xmp"]
466461
transposed_im = ImageOps.exif_transpose(im)
467-
assert transposed_im is not None
468462
assert 0x0112 not in transposed_im.getexif()
469463

470464

src/PIL/ImageOps.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
import operator
2323
import re
2424
from collections.abc import Sequence
25-
from typing import Protocol, cast
25+
from typing import Literal, Protocol, cast, overload
2626

2727
from . import ExifTags, Image, ImagePalette
2828

@@ -673,6 +673,16 @@ def solarize(image: Image.Image, threshold: int = 128) -> Image.Image:
673673
return _lut(image, lut)
674674

675675

676+
@overload
677+
def exif_transpose(image: Image.Image, *, in_place: Literal[True]) -> None: ...
678+
679+
680+
@overload
681+
def exif_transpose(
682+
image: Image.Image, *, in_place: Literal[False] = False
683+
) -> Image.Image: ...
684+
685+
676686
def exif_transpose(image: Image.Image, *, in_place: bool = False) -> Image.Image | None:
677687
"""
678688
If an image has an EXIF Orientation tag, other than 1, transpose the image

0 commit comments

Comments
 (0)