diff options
author | Jordan Cook <jordan.cook@pioneer.com> | 2022-01-15 10:39:48 -0600 |
---|---|---|
committer | Jordan Cook <jordan.cook@pioneer.com> | 2022-01-15 11:09:24 -0600 |
commit | 4c8e386b3a887cdd35c046d426b1247c9018aa0c (patch) | |
tree | 7e62e232694ae8915f0c95b77b8281371b1c1656 | |
parent | 0b8f7c8ba3cdee8408846d9570a3e7ac3a0eb98d (diff) | |
download | requests-cache-4c8e386b3a887cdd35c046d426b1247c9018aa0c.tar.gz |
Switch to a different method of resolving ForwardRefs during deserialization for python 3.10.2 compatibility
-rw-r--r-- | HISTORY.md | 3 | ||||
-rw-r--r-- | requests_cache/serializers/cattrs.py | 8 |
2 files changed, 6 insertions, 5 deletions
@@ -1,7 +1,8 @@ # History ## 0.9.1 (Unreleased) -* Add support for key-only request parameters +* Add support for python 3.10.2 (regarding resolving `ForwardRef` types during deserialization) +* Add support for key-only request parameters (regarding hashing request data for cache key creation) * Reduce verbosity of log messages when encountering an invalid JSON request body ## 0.9.0 (2022-01-01) diff --git a/requests_cache/serializers/cattrs.py b/requests_cache/serializers/cattrs.py index 7b483d7..7652cad 100644 --- a/requests_cache/serializers/cattrs.py +++ b/requests_cache/serializers/cattrs.py @@ -65,10 +65,10 @@ def init_converter(factory: Callable[..., GenConverter] = None): converter.register_unstructure_hook(HTTPHeaderDict, dict) converter.register_structure_hook(HTTPHeaderDict, lambda obj, cls: HTTPHeaderDict(obj)) - # Tell cattrs that a 'CachedResponse' forward ref is equivalent to the CachedResponse class - converter.register_structure_hook( - ForwardRef('CachedResponse'), - lambda obj, cls: converter.structure(obj, CachedResponse), + # Tell cattrs to resolve forward references (required for CachedResponse.history) + converter.register_structure_hook_func( + lambda cls: cls.__class__ is ForwardRef, + lambda obj, cls: converter.structure(obj, cls.__forward_value__), ) return converter |