summaryrefslogtreecommitdiff
path: root/requests_cache/_utils.py
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/_utils.py
parentca26b146592e08ff237cf9b6cccdba56eb2af484 (diff)
downloadrequests-cache-f7281895698f33b9c41239b5be3a961fd1691b99.tar.gz
Update type hints to appease Pylance and stricter mypy settings
Diffstat (limited to 'requests_cache/_utils.py')
-rw-r--r--requests_cache/_utils.py12
1 files changed, 7 insertions, 5 deletions
diff --git a/requests_cache/_utils.py b/requests_cache/_utils.py
index ea6948f..4dbc4ec 100644
--- a/requests_cache/_utils.py
+++ b/requests_cache/_utils.py
@@ -7,9 +7,9 @@ KwargDict = Dict[str, Any]
logger = getLogger('requests_cache')
-def chunkify(iterable: Iterable, max_size: int) -> Iterator[List]:
+def chunkify(iterable: Optional[Iterable], max_size: int) -> Iterator[List]:
"""Split an iterable into chunks of a max size"""
- iterable = list(iterable)
+ iterable = list(iterable or [])
for index in range(0, len(iterable), max_size):
yield iterable[index : index + max_size]
@@ -35,7 +35,7 @@ def encode(value, encoding='utf-8') -> bytes:
return value if isinstance(value, bytes) else str(value).encode(encoding)
-def get_placeholder_class(original_exception: Exception = None):
+def get_placeholder_class(original_exception: Optional[Exception] = None):
"""Create a placeholder type for a class that does not have dependencies installed.
This allows delaying ImportErrors until init time, rather than at import time.
"""
@@ -58,14 +58,16 @@ def get_placeholder_class(original_exception: Exception = None):
return Placeholder
-def get_valid_kwargs(func: Callable, kwargs: Dict, extras: Iterable[str] = None) -> KwargDict:
+def get_valid_kwargs(
+ func: Callable, kwargs: Dict, extras: Optional[Iterable[str]] = None
+) -> KwargDict:
"""Get the subset of non-None ``kwargs`` that are valid arguments for ``func``"""
kwargs, _ = split_kwargs(func, kwargs, extras)
return {k: v for k, v in kwargs.items() if v is not None}
def split_kwargs(
- func: Callable, kwargs: Dict, extras: Iterable[str] = None
+ func: Callable, kwargs: Dict, extras: Optional[Iterable[str]] = None
) -> Tuple[KwargDict, KwargDict]:
"""Split ``kwargs`` into two dicts: those that are valid arguments for ``func``, and those that
are not