Skip to content

Commit dd2bc45

Browse files
authored
Merge pull request #530 from nextstrain/fix-pyright-requests
Fix pyright errors for requests
2 parents ec921c4 + 99793d9 commit dd2bc45

3 files changed

Lines changed: 8 additions & 7 deletions

File tree

nextstrain/cli/pathogens.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -454,9 +454,11 @@ def setup(self, dry_run: bool = False, force: bool = False) -> SetupStatus:
454454
""") from err
455455

456456
except requests.exceptions.HTTPError as err:
457+
assert err.response is not None
457458
if 400 <= err.response.status_code <= 499:
459+
auth = err.response.request.headers["Authorization"]
458460
if (err.response.status_code in {401, 403}
459-
and (auth := err.response.request.headers["Authorization"])
461+
and isinstance(auth, str)
460462
and auth.startswith("Basic ")):
461463
user = b64decode(auth.split(" ", 1)[1]).decode("utf-8").split(":", 1)[0]
462464

@@ -536,7 +538,6 @@ def setup(self, dry_run: bool = False, force: bool = False) -> SetupStatus:
536538
may be worth waiting a little bit and trying again a few
537539
more times.
538540
""", urls = request_list(err.response)) from err
539-
540541
else:
541542
raise err
542543

nextstrain/cli/remote/nextstrain_dot_org.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -390,8 +390,8 @@ def download(url: URL, local_path: Path, recursively: bool = False, dry_run: boo
390390
continue
391391

392392
# Stream response data to local file
393-
with destination.open("w") as local_file:
394-
for chunk in response.iter_content(chunk_size = None, decode_unicode = True):
393+
with destination.open("wb") as local_file:
394+
for chunk in response.iter_content(chunk_size = None):
395395
local_file.write(chunk)
396396

397397

@@ -824,7 +824,7 @@ def raise_for_status(origin: Origin, response: requests.Response) -> None:
824824
response.raise_for_status()
825825

826826
except requests.exceptions.HTTPError as err:
827-
assert type(err.response) is requests.Response
827+
assert err.response is not None
828828
status = err.response.status_code
829829

830830
if status == 400:
@@ -933,7 +933,7 @@ def raise_for_status(origin: Origin, response: requests.Response) -> None:
933933
raise
934934

935935

936-
def authn_challenge(response: requests.Response) -> Optional[Dict[str, str]]:
936+
def authn_challenge(response: requests.Response) -> Optional[dict[str, Optional[str]]]:
937937
"""
938938
Extract the Bearer authentication challenge parameters from the HTTP
939939
``WWW-Authenticate`` header of *response*.

nextstrain/cli/requests.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ def default_user_agent(minimal: bool = USER_AGENT_MINIMAL) -> str:
8787

8888
tty = "yes" if any(os.isatty(fd) for fd in [0, 1, 2]) else "no"
8989

90-
return f"Nextstrain-CLI/{__version__} (https://nextstrain.org/cli) Python/{py_version} python-requests/{requests.__version__} platform/{system}-{machine} installer/{installer} tty/{tty}"
90+
return f"Nextstrain-CLI/{__version__} (https://nextstrain.org/cli) Python/{py_version} python-requests/{requests.__version__} platform/{system}-{machine} installer/{installer} tty/{tty}" # type: ignore[reportPrivateImportUsage]
9191

9292

9393
def version_info_to_str(version_info: Tuple[int, int, int, str, int]) -> str:

0 commit comments

Comments
 (0)