Skip to content

Commit

Permalink
dev: Add type stubs for boto3 and botocore
Browse files Browse the repository at this point in the history
Without these type stubs, new failures related to these libraries are
raised by Pyright starting with 1.1.309:

    …/nextstrain/cli/remote/s3.py
      …/nextstrain/cli/remote/s3.py:213:39 - error: Cannot access member "Bucket" for type "_"
        Member "Bucket" is unknown (reportGeneralTypeIssues)
    …/nextstrain/cli/runner/aws_batch/s3.py
      …/nextstrain/cli/runner/aws_batch/s3.py:208:26 - error: "client" is not a known member of "None" (reportOptionalMemberAccess)
      …/nextstrain/cli/runner/aws_batch/s3.py:212:24 - error: Cannot access member "Bucket" for type "_"
        Member "Bucket" is unknown (reportGeneralTypeIssues)
    3 errors, 0 warnings, 0 informations

With these type stubs, those failures are resolved, but different
failures are raised:

    …/nextstrain/cli/remote/s3.py
      …/nextstrain/cli/remote/s3.py:251:23 - error: Could not access item in TypedDict
        "Error" is not a required key in "_ClientErrorResponseTypeDef", so access may result in runtime exception (reportTypedDictNotRequiredAccess)
      …/nextstrain/cli/remote/s3.py:251:23 - error: Could not access item in TypedDict
        "Code" is not a required key in "_ClientErrorResponseError", so access may result in runtime exception (reportTypedDictNotRequiredAccess)
    2 errors, 0 warnings, 0 informations

All failures are fixed in this commit.

Resolves: <#284>
  • Loading branch information
tsibley committed May 25, 2023
1 parent dee8903 commit 845f067
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 1 deletion.
2 changes: 1 addition & 1 deletion nextstrain/cli/remote/s3.py
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ def exists(object: S3Object) -> bool:
object.load()
return True
except ClientError as error:
if 404 == int(error.response['Error']['Code']):
if 404 == int(error.response.get("Error", {}).get("Code", 0)):
return False
else:
raise
Expand Down
2 changes: 2 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,8 @@ def find_namespaced_packages(namespace):
"sphinx-autobuild",
"sphinx-markdown-tables !=0.0.16",
"sphinx_rtd_theme",
"types-boto3",
"types-botocore",
"types-docutils",
"types-setuptools",
"types-requests; python_version != '3.6'",
Expand Down

0 comments on commit 845f067

Please sign in to comment.