From b0fa6d86233f8e6602c9f3e087581cc78ccce612 Mon Sep 17 00:00:00 2001 From: Andrew Murray Date: Fri, 2 Oct 2026 15:56:43 +1000 Subject: [PATCH] Use set, rather than sorting list --- src/PIL/PsdImagePlugin.py | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/src/PIL/PsdImagePlugin.py b/src/PIL/PsdImagePlugin.py index 4bd6b3b90aa..7d23b1f7110 100644 --- a/src/PIL/PsdImagePlugin.py +++ b/src/PIL/PsdImagePlugin.py @@ -215,7 +215,7 @@ def read(size: int) -> bytes: x1 = si32(read(4)) # image info - bands = [] + bands = set() ct_types = i16(read(2)) if ct_types > 4: fp.seek(ct_types * 6 + 12, io.SEEK_CUR) @@ -233,16 +233,15 @@ def read(size: int) -> bytes: else: b = "" - bands.append(b) + bands.add(b) read(4) # size # figure out the image mode - bands.sort() - if bands == ["R"]: + if bands == {"R"}: mode = "L" - elif bands == ["B", "G", "R"]: + elif bands == {"R", "G", "B"}: mode = "RGB" - elif bands == ["A", "B", "G", "R"]: + elif bands == {"R", "G", "B", "A"}: mode = "RGBA" else: mode = "" # unknown