From ec078744cabc4a3da165a9113ae2add743367792 Mon Sep 17 00:00:00 2001 From: Umar Butler Date: Wed, 20 Mar 2024 22:40:15 +1100 Subject: [PATCH] Fixed a bug causing `cache()` to raise a `TypeError` when attempting to cache a function call that contains an argument that is a list containing a dictionary (#3). --- CHANGELOG.md | 4 ++++ src/persist_cache/serialization.py | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7ce07ec..b972412 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,10 @@ ## Changelog 🔄 All notable changes to `persist-cache` will be documented here. This project adheres to [Keep a Changelog](https://keepachangelog.com/en/1.1.0/) and [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## [0.3.1] - 2024-03-20 +### Fixed +- Fixed a bug causing `cache()` to raise a `TypeError` when attempting to cache a function call that contains an argument that is a list containing a dictionary ([#3](https://github.com/umarbutler/persist-cache/issues/3)) ([fe7aa6c](https://github.com/umarbutler/persist-cache/commit/fe7aa6ccd2f7fbeebaa53e4c1cc0230f6ef35cb4)). + ## [0.3.0] - 2024-03-19 ### Changed - Ceased delimiting hashes and the length of the input with hyphens as the hashes already have a fixed size so there is no possibility of collision. diff --git a/src/persist_cache/serialization.py b/src/persist_cache/serialization.py index 15021b3..23cac99 100644 --- a/src/persist_cache/serialization.py +++ b/src/persist_cache/serialization.py @@ -56,7 +56,7 @@ def directly_msgpackable(data: Any) -> bool: # - It is of a type specified by `ABSOLUTELY_DIRECTLY_MSGPACKABLE_TYPES`. if (isinstance(data, str) and not any(data.startswith(str_signature) for str_signature in STR_SIGNATURES)) \ or isinstance(data, int) and -2**63 <= data <= 2**64-1 \ - or (isinstance(data, list) and all(directly_msgpackable(d) for d in data) and (len(data) == 0 or data[0] not in LISTED_SIGNATURES)) \ + or (isinstance(data, list) and all(directly_msgpackable(d) for d in data) and (len(data) == 0 or not isinstance(data[0], str) or data[0] not in LISTED_SIGNATURES)) \ or (isinstance(data, dict) and all(directly_msgpackable(k) and directly_msgpackable(v) for k, v in data.items())) \ or isinstance(data, ABSOLUTELY_DIRECTLY_MSGPACKABLE_TYPES): return True