Control: tags -1 patch fixed-upstream Please find the upstream patch attached.
Origin: backport, 188d647b052c699941ab85d5b741aa2216ea019a From: Edgar Ramírez-Mondragón <[email protected]> Date: Sun, 10 May 2026 18:46:55 -0600 Subject: fix: Prepare `CachedResponse` dataclass to work with upcoming v2.34
Signed-off-by: Edgar Ramírez-Mondragón <[email protected]> --- pyproject.toml | 1 + requests_cache/serializers/cattrs.py | 11 +++++++++++ uv.lock | 21 ++++++++++++++------- 3 files changed, 26 insertions(+), 7 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 217a3d6b..636d69cc 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -79,6 +79,7 @@ dev = [ 'pytest-pretty >=1.2', 'pytest-rerunfailures >=10.1', 'pytest-xdist >=2.2', + 'requests >=2.22.0.dev0', # Use a prerelease if it's the latest version 'requests-mock ~=1.12', 'responses >=0.19', 'tenacity ~=8.0', diff --git a/requests_cache/serializers/cattrs.py b/requests_cache/serializers/cattrs.py index 82a80733..a791cd69 100644 --- a/requests_cache/serializers/cattrs.py +++ b/requests_cache/serializers/cattrs.py @@ -21,7 +21,9 @@ from json import JSONDecodeError from typing import Callable, Dict, ForwardRef, List, Optional, Union +import attrs from cattrs import Converter +from requests.adapters import HTTPAdapter from requests.cookies import RequestsCookieJar, cookiejar_from_dict from requests.exceptions import RequestException from requests.structures import CaseInsensitiveDict @@ -30,6 +32,15 @@ from ..models import CachedResponse, DecodedContent from .pipeline import Stage +# requests/models.py uses `from __future__ import annotations` and imports RequestsCookieJar +# and HTTPAdapter under TYPE_CHECKING only, so get_type_hints() can't find them at runtime +# when traversing Response's MRO. Pre-resolve CachedResponse field types now so cattrs +# won't call resolve_types() without the necessary localns. +attrs.resolve_types( + CachedResponse, + localns={'RequestsCookieJar': RequestsCookieJar, 'HTTPAdapter': HTTPAdapter}, +) + try: import ujson as json except ImportError:

