Skip to content

Commit 1230917

Browse files
committed
chore: Use Python match statement where possible
1 parent 1f41281 commit 1230917

5 files changed

Lines changed: 295 additions & 289 deletions

File tree

‎cuda_core/cuda/core/utils/_program_cache/_keys.py‎

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -611,12 +611,13 @@ def hash_extra_payload(self, options: ProgramOptions, update: Callable[[str, byt
611611
if isinstance(item, (tuple, list)) and len(item) == 2:
612612
name, src = item
613613
update("extra_source_name", str(name).encode("utf-8"))
614-
if isinstance(src, str):
615-
update("extra_source_code", src.encode("utf-8"))
616-
elif isinstance(src, (bytes, bytearray)):
617-
update("extra_source_code", bytes(src))
618-
else:
619-
update("extra_source_code", str(src).encode("utf-8"))
614+
match src:
615+
case str():
616+
update("extra_source_code", src.encode("utf-8"))
617+
case bytes() | bytearray():
618+
update("extra_source_code", bytes(src))
619+
case _:
620+
update("extra_source_code", str(src).encode("utf-8"))
620621
else:
621622
# Fallback for unexpected format.
622623
update("extra_source", str(item).encode("utf-8"))

0 commit comments

Comments
 (0)