From 99666dac291da395dc03743fb540277c9da0b7b5 Mon Sep 17 00:00:00 2001 From: Andrew Murray Date: Tue, 25 Jun 2024 22:00:51 +1000 Subject: [PATCH] Simplified casts --- src/PIL/Image.py | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/src/PIL/Image.py b/src/PIL/Image.py index c2eac31c730..e9cf7cebcc4 100644 --- a/src/PIL/Image.py +++ b/src/PIL/Image.py @@ -1113,7 +1113,7 @@ def convert_transparency( if trns is not None: try: new_im.info["transparency"] = new_im.palette.getcolor( - cast(Tuple[int, int, int], trns), # trns was converted to RGB + cast(Tuple[int, ...], trns), # trns was converted to RGB new_im, ) except Exception: @@ -1163,12 +1163,9 @@ def convert_transparency( # crash fail if we leave a bytes transparency in an rgb/l mode. del new_im.info["transparency"] if trns is not None: - if new_im.mode == "P": + if new_im.mode == "P" and new_im.palette: try: - new_im.info["transparency"] = new_im.palette.getcolor( - cast(Tuple[int, int, int], trns), # trns was converted to RGB - new_im, - ) + new_im.info["transparency"] = new_im.palette.getcolor(trns, new_im) except ValueError as e: del new_im.info["transparency"] if str(e) != "cannot allocate more than 256 colors":