Ensure HTTPError.response is not None

The implementation of `HTTPError` in `requests` does not guarantee that
the `response` property will always be set. So we need to ensure it is
not `None` before looking for the return code, for example.

This also makes mypy checks pass again, as `types-request` was updated
in 2.31.0.9 to better match this particular aspect. See:
https://github.com/python/typeshed/pull/10875
This commit is contained in:
Jérémy Bobbio (Lunar) 2023-10-18 10:14:55 +02:00
parent 968ddef295
commit 7344d264e7
7 changed files with 8 additions and 2 deletions

View file

@ -56,6 +56,7 @@ def _if_rate_limited(retry_state) -> bool:
exc = attempt.exception()
return (
isinstance(exc, HTTPError)
and exc.response is not None
and exc.response.status_code == codes.forbidden
and int(exc.response.headers.get("RateLimit-Remaining", "0")) == 0
) or is_retryable_exception(exc)