Set line length to 120 characters (#2599)

This commit is contained in:
Jirka Borovec
2023-07-13 17:37:20 +02:00
committed by GitHub
parent de80ff4b91
commit 13e178a3ab
192 changed files with 1455 additions and 4433 deletions
+14 -44
View File
@@ -58,9 +58,7 @@ class GithubRetry(Retry):
# references the class, not the module (due to re-exporting in github/__init__.py)
__datetime = datetime
def __init__(
self, secondary_rate_wait: float = DEFAULT_SECONDARY_RATE_WAIT, **kwargs
):
def __init__(self, secondary_rate_wait: float = DEFAULT_SECONDARY_RATE_WAIT, **kwargs):
"""
:param secondary_rate_wait: seconds to wait before retrying secondary rate limit errors
:param kwargs: see urllib3.Retry for more arguments
@@ -69,12 +67,8 @@ class GithubRetry(Retry):
# 403 is too broad to be retried, but GitHub API signals rate limits via 403
# we retry 403 and look into the response header via Retry.increment
# to determine if we really retry that 403
kwargs["status_forcelist"] = kwargs.get(
"status_forcelist", list(range(500, 600))
) + [403]
kwargs["allowed_methods"] = kwargs.get(
"allowed_methods", Retry.DEFAULT_ALLOWED_METHODS.union({"GET", "POST"})
)
kwargs["status_forcelist"] = kwargs.get("status_forcelist", list(range(500, 600))) + [403]
kwargs["allowed_methods"] = kwargs.get("allowed_methods", Retry.DEFAULT_ALLOWED_METHODS.union({"GET", "POST"}))
super().__init__(**kwargs)
def new(self, **kw):
@@ -116,30 +110,20 @@ class GithubRetry(Retry):
# we want to fall back to the actual github exception (probably a rate limit error)
# but provide some context why we could not deal with it without another exception
try:
raise RuntimeError(
"Failed to inspect response message"
) from e
raise RuntimeError("Failed to inspect response message") from e
except RuntimeError as e:
raise GithubException(
response.status, content, response.headers
) from e
raise GithubException(response.status, content, response.headers) from e
try:
if Requester.isRateLimitError(message):
rate_type = (
"primary"
if Requester.isPrimaryRateLimitError(message)
else "secondary"
)
rate_type = "primary" if Requester.isPrimaryRateLimitError(message) else "secondary"
self.__log(
logging.DEBUG,
f"Response body indicates retry-able {rate_type} rate limit error: {message}",
)
# check early that we are retrying at all
retry = super().increment(
method, url, response, error, _pool, _stacktrace
)
retry = super().increment(method, url, response, error, _pool, _stacktrace)
# we backoff primary rate limit at least until X-RateLimit-Reset,
# we backoff secondary rate limit at for secondary_rate_wait seconds
@@ -149,12 +133,8 @@ class GithubRetry(Retry):
if "X-RateLimit-Reset" in response.headers:
value = response.headers.get("X-RateLimit-Reset")
if value and value.isdigit():
reset = self.__datetime.fromtimestamp(
int(value), timezone.utc
)
delta = reset - self.__datetime.now(
timezone.utc
)
reset = self.__datetime.fromtimestamp(int(value), timezone.utc)
delta = reset - self.__datetime.now(timezone.utc)
resetBackoff = delta.total_seconds()
if resetBackoff > 0:
@@ -175,9 +155,7 @@ class GithubRetry(Retry):
self.__log(
logging.DEBUG,
f"Retry backoff of {retry_backoff}s exceeds "
f"required rate limit backoff of {backoff}s".replace(
".0s", "s"
),
f"required rate limit backoff of {backoff}s".replace(".0s", "s"),
)
backoff = retry_backoff
@@ -186,9 +164,7 @@ class GithubRetry(Retry):
self.__log(
logging.INFO,
f"Setting next backoff to {backoff}s".replace(
".0s", "s"
),
f"Setting next backoff to {backoff}s".replace(".0s", "s"),
)
retry.get_backoff_time = get_backoff_time # type: ignore
return retry
@@ -197,22 +173,16 @@ class GithubRetry(Retry):
logging.DEBUG,
"Response message does not indicate retry-able error",
)
raise Requester.createException(
response.status, response.headers, content
)
raise Requester.createException(response.status, response.headers, content)
except (MaxRetryError, GithubException):
raise
except Exception as e:
# we want to fall back to the actual github exception (probably a rate limit error)
# but provide some context why we could not deal with it without another exception
try:
raise RuntimeError(
"Failed to determine retry backoff"
) from e
raise RuntimeError("Failed to determine retry backoff") from e
except RuntimeError as e:
raise GithubException(
response.status, content, response.headers
) from e
raise GithubException(response.status, content, response.headers) from e
raise GithubException(response.status, content, response.headers)