Skip to content

Commit

Permalink
chore: make mypy@github happy
Browse files Browse the repository at this point in the history
  • Loading branch information
malconsei committed Oct 16, 2023
1 parent 44302d5 commit 4697726
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 9 deletions.
6 changes: 5 additions & 1 deletion mapillary_tools/authenticate.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,11 @@ def prompt_user_for_user_items(user_name: str) -> types.UserItem:
try:
resp = api_v4.get_upload_token(user_email, user_password)
except requests.HTTPError as ex:
if 400 <= ex.response.status_code < 500:
if (
isinstance(ex, requests.HTTPError)
and isinstance(ex.response, requests.Response)
and 400 <= ex.response.status_code < 500
):
r = ex.response.json()
subcode = r.get("error", {}).get("error_subcode")
if subcode in [1348028, 1348092, 3404005, 1348131]:
Expand Down
19 changes: 13 additions & 6 deletions mapillary_tools/upload.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,12 +62,17 @@ class DirectUploadFileType(enum.Enum):


def wrap_http_exception(ex: requests.HTTPError):
req = ex.request
resp = ex.response
lines = [
f"{ex.request.method} {resp.url}",
f"> HTTP Status: {ex.response.status_code}",
str(resp.content),
]
if isinstance(resp, requests.Response) and isinstance(req, requests.Request):
lines = [
f"{req.method} {resp.url}",
f"> HTTP Status: {resp.status_code}",
str(resp.content),
]
else:
lines = []

return UploadHTTPError("\n".join(lines))


Expand Down Expand Up @@ -713,7 +718,9 @@ def upload(
if isinstance(inner_ex, requests.Timeout):
raise exceptions.MapillaryUploadTimeoutError(str(inner_ex)) from inner_ex

if isinstance(inner_ex, requests.HTTPError):
if isinstance(inner_ex, requests.HTTPError) and isinstance(
inner_ex.response, requests.Response
):
if inner_ex.response.status_code in [400, 401]:
try:
error_body = inner_ex.response.json()
Expand Down
10 changes: 8 additions & 2 deletions mapillary_tools/uploader.py
Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,11 @@ def _extract_upload_md5sum(fp: T.IO[bytes]) -> T.Optional[str]:


def _is_immediate_retry(ex: Exception):
if isinstance(ex, requests.HTTPError) and ex.response.status_code == 412:
if (
isinstance(ex, requests.HTTPError)
and isinstance(ex.response, requests.Response)
and ex.response.status_code == 412
):
try:
resp = ex.response.json()
except json.JSONDecodeError:
Expand All @@ -334,7 +338,9 @@ def _is_retriable_exception(ex: Exception):
if isinstance(ex, (requests.ConnectionError, requests.Timeout)):
return True

if isinstance(ex, requests.HTTPError):
if isinstance(ex, requests.HTTPError) and isinstance(
ex.response, requests.Response
):
if 400 <= ex.response.status_code < 500:
try:
resp = ex.response.json()
Expand Down

0 comments on commit 4697726

Please sign in to comment.