Skip to content

Commit d092e76

Browse files
committed
type fixes
1 parent 457a3f5 commit d092e76

File tree

3 files changed

+12
-23
lines changed

3 files changed

+12
-23
lines changed

src/toil/lib/aws/s3.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
import itertools
1717
import logging
1818
import urllib.parse
19-
from collections.abc import Iterator
19+
from collections.abc import Iterator, MutableSequence
2020
from contextlib import contextmanager
2121
from datetime import timedelta
2222
from io import BytesIO
@@ -31,6 +31,7 @@
3131
from mypy_boto3_s3.literals import BucketLocationConstraintType
3232
from mypy_boto3_s3.service_resource import Bucket
3333
from mypy_boto3_s3.type_defs import (
34+
CompletedPartTypeDef,
3435
GetObjectOutputTypeDef,
3536
HeadObjectOutputTypeDef,
3637
ListMultipartUploadsOutputTypeDef,
@@ -291,7 +292,7 @@ def readFrom(self, readable: IO[Any]) -> None:
291292
Bucket=self.bucket_name, Key=self.file_id, **self.encryption_args
292293
)
293294
upload_id = response["UploadId"]
294-
parts = []
295+
parts: MutableSequence[CompletedPartTypeDef] = []
295296
try:
296297
for part_num in itertools.count():
297298
logger.debug(
@@ -327,7 +328,7 @@ def readFrom(self, readable: IO[Any]) -> None:
327328
# Encryption information is not needed here because the upload was
328329
# not started with a checksum.
329330
response = self.s3_client.complete_multipart_upload(
330-
Bucket=self.bucket_name, # type: ignore
331+
Bucket=self.bucket_name,
331332
Key=self.file_id,
332333
UploadId=upload_id,
333334
MultipartUpload={"Parts": parts},

src/toil/lib/docker.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,14 @@
2323
import requests
2424

2525
import docker
26-
from docker.errors import (
27-
ContainerError, # type: ignore[import-not-found]
26+
from docker.errors import ( # type: ignore[import-not-found]
27+
ContainerError,
2828
ImageNotFound,
2929
NotFound,
3030
create_api_error_from_http_exception,
3131
)
32-
from docker.utils.socket import (
33-
consume_socket_output, # type: ignore[import-not-found]
32+
from docker.utils.socket import ( # type: ignore[import-not-found]
33+
consume_socket_output,
3434
demux_adaptor,
3535
)
3636
from toil.lib.accelerators import get_host_accelerator_numbers

src/toil/wdl/wdltoil.py

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -217,24 +217,12 @@ class FileDigester(Protocol):
217217
def __call__(self, __f: ReadableFileObj, __alg_name: str) -> hashlib._Hash: ...
218218

219219

220-
try:
221-
# Don't do a direct conditional import to the final name here because then
222-
# the polyfill needs *exactly* the signature of file_digest, and not just
223-
# one that can accept all calls we make in the file, or MyPy will complain.
224-
#
225-
# We need to tell MyPy we expect this import to fail, when typechecking on
226-
# pythons that don't have it. But we also need to tell it that it is fine
227-
# if it succeeds, for Pythons that do have it.
228-
#
229-
# TODO: Change to checking sys.version_info because MyPy understands that
230-
# better?
231-
from hashlib import (
232-
file_digest as file_digest_impl,
233-
) # type: ignore[attr-defined,unused-ignore]
220+
if sys.version_info >= (3, 11):
221+
from hashlib import file_digest as file_digest_impl
234222

235223
file_digest: FileDigester = file_digest_impl
236-
except ImportError:
237-
# Polyfill file_digest from 3.11+
224+
else:
225+
238226
def file_digest_fallback_impl(f: ReadableFileObj, alg_name: str) -> hashlib._Hash:
239227
BUFFER_SIZE = 1024 * 1024
240228
hasher = hashlib.new(alg_name)

0 commit comments

Comments
 (0)