summaryrefslogtreecommitdiff
path: root/requests_cache/models
diff options
context:
space:
mode:
authorJordan Cook <jordan.cook.git@proton.me>2022-12-11 22:28:55 -0600
committerJordan Cook <jordan.cook.git@proton.me>2022-12-13 16:27:49 -0600
commitf7281895698f33b9c41239b5be3a961fd1691b99 (patch)
tree233d6439c5f5a9b770a4206aed8fbe26e60d3a94 /requests_cache/models
parentca26b146592e08ff237cf9b6cccdba56eb2af484 (diff)
downloadrequests-cache-f7281895698f33b9c41239b5be3a961fd1691b99.tar.gz
Update type hints to appease Pylance and stricter mypy settings
Diffstat (limited to 'requests_cache/models')
-rw-r--r--requests_cache/models/raw_response.py8
-rwxr-xr-xrequests_cache/models/response.py8
2 files changed, 8 insertions, 8 deletions
diff --git a/requests_cache/models/raw_response.py b/requests_cache/models/raw_response.py
index dfc5591..f95afab 100644
--- a/requests_cache/models/raw_response.py
+++ b/requests_cache/models/raw_response.py
@@ -1,6 +1,6 @@
from io import BytesIO
from logging import getLogger
-from typing import TYPE_CHECKING
+from typing import TYPE_CHECKING, Optional
from attr import define, field, fields_dict
from requests import Response
@@ -37,7 +37,7 @@ class CachedHTTPResponse(RichMixin, HTTPResponse):
strict: int = field(default=0)
version: int = field(default=0)
- def __init__(self, body: bytes = None, **kwargs):
+ def __init__(self, body: Optional[bytes] = None, **kwargs):
"""First initialize via HTTPResponse, then via attrs"""
kwargs = {k: v for k, v in kwargs.items() if v is not None}
super().__init__(body=BytesIO(body or b''), preload_content=False, **kwargs)
@@ -45,7 +45,7 @@ class CachedHTTPResponse(RichMixin, HTTPResponse):
self.__attrs_init__(**kwargs) # type: ignore # False positive in mypy 0.920+?
@classmethod
- def from_response(cls, response: Response):
+ def from_response(cls, response: Response) -> 'CachedHTTPResponse':
"""Create a CachedHTTPResponse based on an original response"""
# Copy basic attributes
raw = response.raw
@@ -94,7 +94,7 @@ class CachedHTTPResponse(RichMixin, HTTPResponse):
self._fp.close()
return data
- def reset(self, body: bytes = None):
+ def reset(self, body: Optional[bytes] = None):
"""Reset raw response file pointer, and optionally update content"""
if body is not None:
self._body = body
diff --git a/requests_cache/models/response.py b/requests_cache/models/response.py
index e704f03..2cd6047 100755
--- a/requests_cache/models/response.py
+++ b/requests_cache/models/response.py
@@ -11,7 +11,7 @@ from requests import PreparedRequest, Response
from requests.cookies import RequestsCookieJar
from requests.structures import CaseInsensitiveDict
-from ..policy.expiration import ExpirationTime, get_expiration_datetime
+from ..policy import ExpirationTime, get_expiration_datetime
from . import CachedHTTPResponse, CachedRequest, RichMixin
if TYPE_CHECKING:
@@ -47,7 +47,7 @@ class OriginalResponse(BaseResponse):
"""Wrapper class for non-cached responses returned by :py:class:`.CachedSession`"""
@classmethod
- def wrap_response(cls, response: Response, actions: 'CacheActions'):
+ def wrap_response(cls, response: Response, actions: 'CacheActions') -> 'OriginalResponse':
"""Modify a response object in-place and add extra cache-related attributes"""
if not isinstance(response, cls):
response.__class__ = cls
@@ -55,7 +55,7 @@ class OriginalResponse(BaseResponse):
response.expires = None if actions.skip_write else actions.expires # type: ignore
response.cache_key = None if actions.skip_write else actions.cache_key # type: ignore
response.created_at = datetime.utcnow() # type: ignore
- return response
+ return response # type: ignore
@define(auto_attribs=False, repr=False, slots=False)
@@ -85,7 +85,7 @@ class CachedResponse(RichMixin, BaseResponse):
self.raw = self.raw or CachedHTTPResponse.from_cached_response(self)
@classmethod
- def from_response(cls, response: Response, **kwargs):
+ def from_response(cls, response: Response, **kwargs) -> 'CachedResponse':
"""Create a CachedResponse based on an original Response or another CachedResponse object"""
if isinstance(response, CachedResponse):
obj = attr.evolve(response, **kwargs)