Skip to content

Commit e9e1a0d

Browse files
committed
Add some more type signatures
1 parent 43a39d0 commit e9e1a0d

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+283
-283
lines changed

odc/geo/_rgba.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
# pylint: disable=import-outside-toplevel
1313

1414

15-
def is_rgb(x: xr.DataArray):
15+
def is_rgb(x: xr.DataArray) -> bool:
1616
"""
1717
Check if array is RGB(A).
1818
"""

odc/geo/_xr_interop.py

+8-8
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ def _get_crs_from_attrs(obj: XarrayObject, sdims: Tuple[str, str]) -> Optional[C
112112
"""
113113
crs_set: Set[CRS] = set()
114114

115-
def _add_candidate(crs):
115+
def _add_candidate(crs) -> None:
116116
if crs is None:
117117
return
118118
if isinstance(crs, str):
@@ -127,11 +127,11 @@ def _add_candidate(crs):
127127
else:
128128
warnings.warn(f"Ignoring crs attribute of type: {type(crs)}")
129129

130-
def process_attrs(attrs):
130+
def process_attrs(attrs) -> None:
131131
_add_candidate(attrs.get("crs", None))
132132
_add_candidate(attrs.get("crs_wkt", None))
133133

134-
def process_datavar(x):
134+
def process_datavar(x) -> None:
135135
process_attrs(x.attrs)
136136
for dim in sdims:
137137
if dim in x.coords:
@@ -910,7 +910,7 @@ class ODCExtension:
910910
Common accessors for both Array/Dataset.
911911
"""
912912

913-
def __init__(self, state: GeoState):
913+
def __init__(self, state: GeoState) -> None:
914914
self._state = state
915915

916916
@property
@@ -987,7 +987,7 @@ class ODCExtensionDa(ODCExtension):
987987
ODC extension for :py:class:`xarray.DataArray`.
988988
"""
989989

990-
def __init__(self, xx: xarray.DataArray):
990+
def __init__(self, xx: xarray.DataArray) -> None:
991991
ODCExtension.__init__(self, _locate_geo_info(xx))
992992
self._xx = xx
993993

@@ -1042,7 +1042,7 @@ def nodata(self) -> Nodata:
10421042
return None
10431043

10441044
@nodata.setter
1045-
def nodata(self, value: Nodata):
1045+
def nodata(self, value: Nodata) -> None:
10461046
nodata = resolve_nodata(value, self._xx.dtype)
10471047

10481048
if nodata is None:
@@ -1069,7 +1069,7 @@ class ODCExtensionDs(ODCExtension):
10691069
ODC extension for :py:class:`xarray.Dataset`.
10701070
"""
10711071

1072-
def __init__(self, ds: xarray.Dataset):
1072+
def __init__(self, ds: xarray.Dataset) -> None:
10731073
ODCExtension.__init__(self, _locate_geo_info(ds))
10741074
self._xx = ds
10751075

@@ -1110,7 +1110,7 @@ def _xarray_geobox(xx: XarrayObject) -> Optional[GeoBox]:
11101110
return None
11111111

11121112

1113-
def register_geobox():
1113+
def register_geobox() -> None:
11141114
"""
11151115
Backwards compatiblity layer for datacube ``.geobox`` property.
11161116
"""

odc/geo/cog/_az.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ def __init__(
4343
blob: str,
4444
credential: Any = None,
4545
client: Any = None,
46-
):
46+
) -> None:
4747
"""
4848
Initialise Azure multipart upload.
4949
@@ -102,7 +102,7 @@ def finalise(self, parts: list[dict[str, Any]]) -> str:
102102
self.blob_client.commit_block_list(block_list)
103103
return self.blob_client.get_blob_properties().etag
104104

105-
def cancel(self, other: str = ""):
105+
def cancel(self, other: str = "") -> None:
106106
"""
107107
Cancel the upload by clearing the block list.
108108
"""
@@ -143,7 +143,7 @@ class DelayedAzureWriter(AzureLimits):
143143
Dask-compatible writer for Azure Blob Storage multipart uploads.
144144
"""
145145

146-
def __init__(self, mpu: AzMultiPartUpload, kw: dict[str, Any]):
146+
def __init__(self, mpu: AzMultiPartUpload, kw: dict[str, Any]) -> None:
147147
"""
148148
Initialise the Azure writer.
149149

odc/geo/cog/_mpu.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ def __repr__(self) -> str:
111111
s = f"{s} final"
112112
return s
113113

114-
def append(self, data: SomeData, chunk_id: Any = None):
114+
def append(self, data: SomeData, chunk_id: Any = None) -> None:
115115
sz = len(data)
116116
self.observed.append((sz, chunk_id))
117117
self.data += data

odc/geo/cog/_rio.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ def _write_cog(
194194

195195
rio_opts.update(extra_rio_opts)
196196

197-
def _write(pix, band, dst):
197+
def _write(pix, band, dst) -> None:
198198
if not use_windowed_writes:
199199
dst.write(pix, band)
200200
else:

odc/geo/cog/_s3.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ def __init__(
8484
profile: Optional[str] = None,
8585
endpoint_url: Optional[str] = None,
8686
creds: Optional["ReadOnlyCredentials"] = None,
87-
):
87+
) -> None:
8888
self.bucket = bucket
8989
self.key = key
9090
self.uploadId = uploadId
@@ -153,7 +153,7 @@ def started(self) -> bool:
153153
"""Check if the multipart upload has been initiated."""
154154
return len(self.uploadId) > 0
155155

156-
def cancel(self, other: str = ""):
156+
def cancel(self, other: str = "") -> None:
157157
"""Cancel the multipart upload."""
158158
uploadId = other if other else self.uploadId
159159
if not uploadId:
@@ -216,7 +216,7 @@ class DelayedS3Writer(S3Limits):
216216

217217
# pylint: disable=import-outside-toplevel,import-error
218218

219-
def __init__(self, mpu: S3MultiPartUpload, kw: dict[str, Any]):
219+
def __init__(self, mpu: S3MultiPartUpload, kw: dict[str, Any]) -> None:
220220
self.mpu = mpu
221221
self.kw = kw # mostly ContentType= kinda thing
222222
self._shared_var: Optional["distributed.Variable"] = None

odc/geo/crs.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ class CRS:
9595

9696
__slots__ = ("_crs", "_epsg", "_str")
9797

98-
def __init__(self, crs_spec: Any):
98+
def __init__(self, crs_spec: Any) -> None:
9999
"""
100100
Construct CRS object from *something*.
101101
@@ -122,8 +122,8 @@ def __init__(self, crs_spec: Any):
122122
def __getstate__(self):
123123
return {"crs_str": self._str}
124124

125-
def __setstate__(self, state):
126-
self.__init__(state["crs_str"])
125+
def __setstate__(self, state) -> None:
126+
self.__init__(state["crs_str"]) # type: ignore[misc]
127127

128128
def to_wkt(self, pretty: bool = False, version: Optional[WktVersion] = None) -> str:
129129
"""

odc/geo/data/__init__.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ class _CachedGeoDataFrame:
5454
_lock = threading.Lock()
5555
_data_url = ""
5656

57-
def __init__(self):
57+
def __init__(self) -> None:
5858
# Thread safe class-cached dataload
5959
if self._instance is None:
6060
with self._lock:

odc/geo/gcp.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ def __init__(
4343
pix: SomePointSet,
4444
wld: SomePointSet,
4545
crs: MaybeCRS = None,
46-
):
46+
) -> None:
4747
pix, _ = _points_to_array(pix)
4848
wld, _crs = _points_to_array(wld)
4949

@@ -143,7 +143,7 @@ class GCPGeoBox(GeoBoxBase):
143143

144144
def __init__(
145145
self, shape: SomeShape, mapping: GCPMapping, affine: Optional[Affine] = None
146-
):
146+
) -> None:
147147
if affine is None:
148148
affine = Affine.identity()
149149
GeoBoxBase.__init__(self, shape, affine, mapping.crs)
@@ -182,7 +182,7 @@ def linear(self) -> bool:
182182
return False
183183

184184
@property
185-
def axis_aligned(self):
185+
def axis_aligned(self) -> bool:
186186
return False
187187

188188
@property
@@ -279,7 +279,7 @@ def zoom_to(
279279
_shape, _affine = self.compute_zoom_to(shape, resolution=resolution)
280280
return GCPGeoBox(_shape, self._mapping, _affine)
281281

282-
def __str__(self):
282+
def __str__(self) -> str:
283283
return self.__repr__()
284284

285285
def __repr__(self) -> str:

odc/geo/geobox.py

+6-6
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ class GeoBoxBase:
116116

117117
__slots__ = ("_shape", "_affine", "_crs", "_extent", "_lazy_ui")
118118

119-
def __init__(self, shape: SomeShape, affine: Affine, crs: MaybeCRS):
119+
def __init__(self, shape: SomeShape, affine: Affine, crs: MaybeCRS) -> None:
120120
shape = shape_(shape)
121121

122122
self._shape = shape
@@ -511,7 +511,7 @@ class GeoBox(GeoBoxBase):
511511

512512
__slots__ = ()
513513

514-
def __init__(self, shape: SomeShape, affine: Affine, crs: MaybeCRS):
514+
def __init__(self, shape: SomeShape, affine: Affine, crs: MaybeCRS) -> None:
515515
GeoBoxBase.__init__(self, shape, affine, crs)
516516

517517
@staticmethod
@@ -891,10 +891,10 @@ def to_crs(
891891
tol=tol,
892892
)
893893

894-
def __str__(self):
894+
def __str__(self) -> str:
895895
return self.__repr__()
896896

897-
def __repr__(self):
897+
def __repr__(self) -> str:
898898
return f"GeoBox({self._shape.yx!r}, {self._affine!r}, {self._crs!r})"
899899

900900
def __eq__(self, other):
@@ -1340,7 +1340,7 @@ def __init__(
13401340
tile_shape: Union[SomeShape, Chunks2d, None],
13411341
*,
13421342
_tiles: Optional[RoiTiles] = None,
1343-
):
1343+
) -> None:
13441344
"""
13451345
Construct from a :py:class:`~odc.geo.GeoBox`.
13461346
@@ -1546,7 +1546,7 @@ def __dask_tokenize__(self):
15461546
*self._tiles.__dask_tokenize__()[1:],
15471547
)
15481548

1549-
def __str__(self):
1549+
def __str__(self) -> str:
15501550
return str(self.roi)
15511551

15521552
def __eq__(self, __value: object) -> bool:

odc/geo/geom.py

+6-6
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ class BoundingBox(Sequence[float]):
4949

5050
def __init__(
5151
self, left: float, bottom: float, right: float, top: float, crs: MaybeCRS = None
52-
):
52+
) -> None:
5353
self._box = (left, bottom, right, top)
5454
self._crs = norm_crs(crs)
5555

@@ -498,7 +498,7 @@ def __init__(
498498
self,
499499
geom: Union[base.BaseGeometry, Dict[str, Any], "Geometry"],
500500
crs: MaybeCRS = None,
501-
):
501+
) -> None:
502502
if isinstance(geom, Geometry):
503503
assert crs is None
504504
self.crs: Optional[CRS] = geom.crs
@@ -924,10 +924,10 @@ def __eq__(self, other: Any) -> bool:
924924
and self.geom == other.geom
925925
)
926926

927-
def __str__(self):
927+
def __str__(self) -> str:
928928
return f"Geometry({self.__geo_interface__}, {self.crs!r})"
929929

930-
def __repr__(self):
930+
def __repr__(self) -> str:
931931
return f"Geometry({self.geom}, {self.crs})"
932932

933933
# Implement pickle/unpickle
@@ -936,8 +936,8 @@ def __repr__(self):
936936
def __getstate__(self):
937937
return {"geom": self.json, "crs": self.crs}
938938

939-
def __setstate__(self, state):
940-
self.__init__(**state)
939+
def __setstate__(self, state) -> None:
940+
self.__init__(**state) # type: ignore[misc]
941941

942942
@property
943943
def is_multi(self) -> bool:

odc/geo/gridspec.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ def __init__(
5454
origin: Optional[XY[float]] = None,
5555
flipx: bool = False,
5656
flipy: bool = False,
57-
):
57+
) -> None:
5858
tile_shape = shape_(tile_shape)
5959
resolution = res_(resolution)
6060

odc/geo/math.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -653,7 +653,7 @@ class Bin1D:
653653

654654
__slots__ = ("sz", "origin", "direction")
655655

656-
def __init__(self, sz: float, origin: float = 0.0, direction: Literal[1, -1] = 1):
656+
def __init__(self, sz: float, origin: float = 0.0, direction: Literal[1, -1] = 1) -> None:
657657
"""
658658
Construct :py:class:`~odc.geo.math.Bin1D` object.
659659

odc/geo/overlap.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ class LinearPointTransform:
5353
Point transform within the same projection.
5454
"""
5555

56-
def __init__(self, A: Affine, back: Optional["LinearPointTransform"] = None):
56+
def __init__(self, A: Affine, back: Optional["LinearPointTransform"] = None) -> None:
5757
self.A = A
5858
self._back = back
5959

@@ -98,7 +98,7 @@ def __init__(
9898
src: GeoBoxBase,
9999
dst: GeoBoxBase,
100100
back: Optional["GbxPointTransform"] = None,
101-
):
101+
) -> None:
102102
assert src.crs is not None and dst.crs is not None
103103
self._src = src
104104
self._dst = dst

odc/geo/roi.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ def chunks(self) -> Chunks2d: ...
7777

7878
def locate(self, pix: SomeIndex2d) -> Tuple[int, int]: ...
7979

80-
def __dask_tokenize__(self): ...
80+
def __dask_tokenize__(self) -> None: ...
8181

8282

8383
def norm_slice_2d(
@@ -88,7 +88,7 @@ def norm_slice_2d(
8888
return roi_normalise(iyx_(idx).yx, shape)
8989

9090

91-
def _fmt_shape(shape):
91+
def _fmt_shape(shape) -> str:
9292
n1, n2 = shape.yx
9393
if max(n1, n2) > 10_000:
9494
return f"{n1:_d}x{n2:_d}"

odc/geo/types.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -482,7 +482,7 @@ class _Func2Map(Mapping[TK, TV]):
482482

483483
__slots__ = ("_func", "_keys")
484484

485-
def __init__(self, func: Callable[[TK], TV], keys: Sequence[TK]):
485+
def __init__(self, func: Callable[[TK], TV], keys: Sequence[TK]) -> None:
486486
self._func = func
487487
self._keys = keys
488488

odc/geo/ui.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ def svg_base_map(
8484
sz=360,
8585
map_svg_path=None,
8686
target=None,
87-
):
87+
) -> str:
8888
clip_bbox = None
8989
if bbox is not None:
9090
clip_bbox = geom.bbox_intersection(
@@ -140,7 +140,7 @@ def make_svg(
140140
stroke_width=1,
141141
bbox=None,
142142
sz=360,
143-
):
143+
) -> str:
144144
if bbox is None:
145145
bbox = (0, 0, sz, sz)
146146

0 commit comments

Comments
 (0)