chore: fix mypy false positive
We have some code that handles multiple versions of urllib3, but mypy
always complains about one version or the other.
CI has been passing, but I've been seeing false positives on my machine.
This approach should work in both cases.
@@ -7,7 +7,18 @@ import pathlib
import platform
import random
import sys
-from typing import IO, Any, Callable, Iterator, Optional, Sequence, TypeVar, Union, overload
+from typing import (
+ IO,
+ Any,
+ Callable,
+ Iterator,
+ Optional,
+ Sequence,
+ TypeVar,
+ Union,
+ no_type_check,
+ overload,
+)
import urllib3
@@ -160,7 +171,9 @@ def get_max_retries_config() -> urllib3.util.retry.Retry:
config = json.loads(config_data)
return urllib3.util.retry.Retry(**config)
- # Defaults.
+ # Default retry is different with different versions of urllib3, which mypy doesn't understand.
+ @no_type_check
+ def make_default_retry():
try:
return urllib3.util.retry.Retry(
total=20,
@@ -171,9 +184,11 @@ def get_max_retries_config() -> urllib3.util.retry.Retry:
return urllib3.util.retry.Retry(
total=20,
backoff_factor=0.5,
- method_whitelist=False, # type: ignore
+ method_whitelist=False,
)
+ return make_default_retry() # type: ignore
+
def parse_protobuf_timestamp(ts: str) -> datetime.datetime:
# Protobuf emits timestamps in RFC3339 format, which are identical to canonical JavaScript date
