Skip to content

Commit

Permalink
Merge pull request #503 from JWCook/py3.10.2-compat
Browse files Browse the repository at this point in the history
Switch to a different method of resolving ForwardRefs during deserialization for python 3.10.2 compatibility
  • Loading branch information
JWCook committed Jan 15, 2022
2 parents 0b8f7c8 + 4c8e386 commit ddf7ad8
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
3 changes: 2 additions & 1 deletion HISTORY.md
@@ -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)
Expand Down
8 changes: 4 additions & 4 deletions requests_cache/serializers/cattrs.py
Expand Up @@ -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
Expand Down

0 comments on commit ddf7ad8

Please sign in to comment.