Skip to content

Commit

Permalink
Updated casts
Browse files Browse the repository at this point in the history
  • Loading branch information
radarhere committed Jun 24, 2024
1 parent 3cebb55 commit dfc1b0f
Showing 1 changed file with 3 additions and 6 deletions.
9 changes: 3 additions & 6 deletions src/PIL/Image.py
Original file line number Diff line number Diff line change
Expand Up @@ -1103,7 +1103,7 @@ def convert_transparency(m, v):
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:
Expand Down Expand Up @@ -1153,12 +1153,9 @@ def convert_transparency(m, v):
# 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":
Expand Down

0 comments on commit dfc1b0f

Please sign in to comment.