Skip to content

Commit ad98235

Browse files
committed
fix: mypy errors in cog module
1 parent bc8811c commit ad98235

File tree

3 files changed

+26
-19
lines changed

3 files changed

+26
-19
lines changed

odc/geo/cog/_az.py

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
from typing import Any, Union
33

44
import dask
5+
from dask.delayed import Delayed
56

67
from ._mpu import mpu_write
78
from ._multipart import MultiPartUploadBase
@@ -33,6 +34,12 @@ def max_part(self) -> int:
3334

3435

3536
class AzMultiPartUpload(AzureLimits, MultiPartUploadBase):
37+
"""
38+
Azure Blob Storage multipart upload.
39+
"""
40+
41+
# pylint: disable=too-many-instance-attributes
42+
3643
def __init__(
3744
self, account_url: str, container: str, blob: str, credential: Any = None
3845
):
@@ -94,10 +101,11 @@ def finalise(self, parts: list[dict[str, Any]]) -> str:
94101
self.blob_client.commit_block_list(block_list)
95102
return self.blob_client.get_blob_properties().etag
96103

97-
def cancel(self):
104+
def cancel(self, other: str = ""):
98105
"""
99106
Cancel the upload by clearing the block list.
100107
"""
108+
assert other == ""
101109
self.block_ids.clear()
102110

103111
@property
@@ -118,7 +126,7 @@ def started(self) -> bool:
118126
"""
119127
return bool(self.block_ids)
120128

121-
def writer(self, kw: dict[str, Any], client: Any = None):
129+
def writer(self, kw: dict[str, Any], *, client: Any = None):
122130
"""
123131
Return a stateless writer compatible with Dask.
124132
"""
@@ -130,12 +138,12 @@ def upload(
130138
*,
131139
mk_header: Any = None,
132140
mk_footer: Any = None,
133-
user_kw: dict[str, Any] = None,
141+
user_kw: dict[str, Any] | None = None,
134142
writes_per_chunk: int = 1,
135143
spill_sz: int = 20 * (1 << 20),
136144
client: Any = None,
137145
**kw,
138-
) -> dask.delayed.Delayed:
146+
) -> Delayed:
139147
"""
140148
Upload chunks to Azure Blob Storage with multipart uploads.
141149

odc/geo/cog/_multipart.py

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,11 @@
77
"""
88

99
from abc import ABC, abstractmethod
10-
from typing import Any, Union
10+
from typing import Any, Union, TYPE_CHECKING
1111

12-
import dask.bag
12+
if TYPE_CHECKING:
13+
# pylint: disable=import-outside-toplevel,import-error
14+
import dask.bag
1315

1416

1517
class MultiPartUploadBase(ABC):
@@ -18,34 +20,28 @@ class MultiPartUploadBase(ABC):
1820
@abstractmethod
1921
def initiate(self, **kwargs) -> str:
2022
"""Initiate a multipart upload and return an identifier."""
21-
pass
2223

2324
@abstractmethod
2425
def write_part(self, part: int, data: bytes) -> dict[str, Any]:
2526
"""Upload a single part."""
26-
pass
2727

2828
@abstractmethod
2929
def finalise(self, parts: list[dict[str, Any]]) -> str:
3030
"""Finalise the upload with a list of parts."""
31-
pass
3231

3332
@abstractmethod
3433
def cancel(self, other: str = ""):
3534
"""Cancel the multipart upload."""
36-
pass
3735

3836
@property
3937
@abstractmethod
4038
def url(self) -> str:
4139
"""Return the URL of the upload target."""
42-
pass
4340

4441
@property
4542
@abstractmethod
4643
def started(self) -> bool:
4744
"""Check if the multipart upload has been initiated."""
48-
pass
4945

5046
@abstractmethod
5147
def writer(self, kw: dict[str, Any], *, client: Any = None) -> Any:
@@ -55,7 +51,6 @@ def writer(self, kw: dict[str, Any], *, client: Any = None) -> Any:
5551
:param kw: Additional parameters for the writer.
5652
:param client: Dask client for distributed execution.
5753
"""
58-
pass
5954

6055
@abstractmethod
6156
def upload(
@@ -64,7 +59,7 @@ def upload(
6459
*,
6560
mk_header: Any = None,
6661
mk_footer: Any = None,
67-
user_kw: dict[str, Any] = None,
62+
user_kw: dict[str, Any] | None = None,
6863
writes_per_chunk: int = 1,
6964
spill_sz: int = 20 * (1 << 20),
7065
client: Any = None,
@@ -82,4 +77,3 @@ def upload(
8277
:param client: Dask client for distributed execution.
8378
:return: A Dask delayed object representing the finalised upload.
8479
"""
85-
pass

odc/geo/cog/_tifffile.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
from ..types import Shape2d, SomeNodata, Unset, shape_
2525
from ._mpu import mpu_write
2626
from ._mpu_fs import MPUFileSink
27+
from ._multipart import MultiPartUploadBase
2728

2829
from ._shared import (
2930
GDAL_COMP,
@@ -736,22 +737,26 @@ def save_cog_with_dask(
736737
# Determine output type and initiate uploader
737738
parsed_url = urlparse(dst)
738739
if parsed_url.scheme == "s3":
739-
if have.s3:
740+
if have.botocore:
740741
from ._s3 import S3MultiPartUpload, s3_parse_url
741742

742743
bucket, key = s3_parse_url(dst)
743-
uploader = S3MultiPartUpload(bucket, key, **aws)
744+
uploader: MultiPartUploadBase = S3MultiPartUpload(bucket, key, **aws)
744745
else:
745746
raise RuntimeError("Please install `boto3` to use S3")
746747
elif parsed_url.scheme == "az":
747748
if have.azure:
748749
from ._az import AzMultiPartUpload
749750

751+
assert azure is not None
752+
assert "account_url" in azure
753+
assert "credential" in azure
754+
750755
uploader = AzMultiPartUpload(
751-
account_url=azure.get("account_url"),
756+
account_url=azure["account_url"],
752757
container=parsed_url.netloc,
753758
blob=parsed_url.path.lstrip("/"),
754-
credential=azure.get("credential"),
759+
credential=azure["credential"],
755760
)
756761
else:
757762
raise RuntimeError("Please install `azure-storage-blob` to use Azure")

0 commit comments

Comments
 (0)