summaryrefslogtreecommitdiff
path: root/requests_cache/serializers
diff options
context:
space:
mode:
authorJordan Cook <jordan.cook@pioneer.com>2022-01-15 10:39:48 -0600
committerJordan Cook <jordan.cook@pioneer.com>2022-01-15 11:09:24 -0600
commit4c8e386b3a887cdd35c046d426b1247c9018aa0c (patch)
tree7e62e232694ae8915f0c95b77b8281371b1c1656 /requests_cache/serializers
parent0b8f7c8ba3cdee8408846d9570a3e7ac3a0eb98d (diff)
downloadrequests-cache-4c8e386b3a887cdd35c046d426b1247c9018aa0c.tar.gz
Switch to a different method of resolving ForwardRefs during deserialization for python 3.10.2 compatibility
Diffstat (limited to 'requests_cache/serializers')
-rw-r--r--requests_cache/serializers/cattrs.py8
1 files changed, 4 insertions, 4 deletions
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