diff options
author | Jordan Cook <jordan.cook.git@proton.me> | 2022-12-11 22:28:55 -0600 |
---|---|---|
committer | Jordan Cook <jordan.cook.git@proton.me> | 2022-12-13 16:27:49 -0600 |
commit | f7281895698f33b9c41239b5be3a961fd1691b99 (patch) | |
tree | 233d6439c5f5a9b770a4206aed8fbe26e60d3a94 /requests_cache/policy | |
parent | ca26b146592e08ff237cf9b6cccdba56eb2af484 (diff) | |
download | requests-cache-f7281895698f33b9c41239b5be3a961fd1691b99.tar.gz |
Update type hints to appease Pylance and stricter mypy settings
Diffstat (limited to 'requests_cache/policy')
-rw-r--r-- | requests_cache/policy/actions.py | 14 | ||||
-rw-r--r-- | requests_cache/policy/expiration.py | 6 |
2 files changed, 14 insertions, 6 deletions
diff --git a/requests_cache/policy/actions.py b/requests_cache/policy/actions.py index bc59c13..50960cb 100644 --- a/requests_cache/policy/actions.py +++ b/requests_cache/policy/actions.py @@ -14,11 +14,12 @@ from . import ( NEVER_EXPIRE, CacheDirectives, ExpirationTime, + KeyCallback, get_expiration_datetime, get_expiration_seconds, get_url_expiration, ) -from .settings import CacheSettings, KeyCallback +from .settings import CacheSettings if TYPE_CHECKING: from ..models import CachedResponse @@ -71,7 +72,9 @@ class CacheActions(RichMixin): _validation_headers: Dict[str, str] = field(factory=dict, repr=False) @classmethod - def from_request(cls, cache_key: str, request: PreparedRequest, settings: CacheSettings = None): + def from_request( + cls, cache_key: str, request: PreparedRequest, settings: Optional[CacheSettings] = None + ): """Initialize from request info and cache settings. Note on refreshing: `must-revalidate` isn't a standard request header, but is used here to @@ -133,7 +136,7 @@ class CacheActions(RichMixin): """ return get_expiration_datetime(self.expire_after) - def is_usable(self, cached_response: 'CachedResponse', error: bool = False): + def is_usable(self, cached_response: Optional['CachedResponse'], error: bool = False): """Determine whether a given cached response is "fresh enough" to satisfy the request, based on: @@ -163,7 +166,10 @@ class CacheActions(RichMixin): return datetime.utcnow() < cached_response.expires + offset def update_from_cached_response( - self, cached_response: 'CachedResponse', create_key: KeyCallback = None, **key_kwargs + self, + cached_response: Optional['CachedResponse'], + create_key: Optional[KeyCallback] = None, + **key_kwargs, ): """Determine if we can reuse a cached response, or set headers for a conditional request if possible. diff --git a/requests_cache/policy/expiration.py b/requests_cache/policy/expiration.py index 256ab91..18a2593 100644 --- a/requests_cache/policy/expiration.py +++ b/requests_cache/policy/expiration.py @@ -18,7 +18,9 @@ logger = getLogger(__name__) def get_expiration_datetime( - expire_after: ExpirationTime, start_time: datetime = None, negative_delta: bool = False + expire_after: ExpirationTime, + start_time: Optional[datetime] = None, + negative_delta: bool = False, ) -> Optional[datetime]: """Convert an expiration value in any supported format to an absolute datetime""" # Never expire (or do not cache, in which case expiration won't be used) @@ -50,7 +52,7 @@ def get_expiration_seconds(expire_after: ExpirationTime) -> int: def get_url_expiration( - url: Optional[str], urls_expire_after: ExpirationPatterns = None + url: Optional[str], urls_expire_after: Optional[ExpirationPatterns] = None ) -> ExpirationTime: """Check for a matching per-URL expiration, if any""" if not url: |