Skip to content

Commit 01c924a

Browse files
committed
Fix several more type annotations
1 parent 72b1fb7 commit 01c924a

20 files changed

+113
-55
lines changed

docs/conf.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
import os
1616
import sys
1717
import subprocess
18+
from typing import Any, Dict
19+
1820
sys.path.insert(0, os.path.abspath('.'))
1921
sys.path.insert(0, os.path.abspath('../'))
2022
from pystac.version import __version__
@@ -134,7 +136,7 @@
134136

135137
# -- Options for LaTeX output ------------------------------------------------
136138

137-
latex_elements = {
139+
latex_elements: Dict[str, Any] = {
138140
# The paper size ('letterpaper' or 'a4paper').
139141
#
140142
# 'papersize': 'letterpaper',

pystac/extensions/base.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@ class PropertiesExtension(ABC):
2828
properties: Dict[str, Any]
2929
additional_read_properties: Optional[Iterable[Dict[str, Any]]] = None
3030

31-
def _get_property(self, prop_name: str, typ: Type[P] = Type[Any]) -> Optional[P]:
32-
result: Optional[typ] = self.properties.get(prop_name)
31+
def _get_property(self, prop_name: str, typ: Type[P]) -> Optional[P]:
32+
result = self.properties.get(prop_name)
3333
if result is not None:
3434
return result
3535
if self.additional_read_properties is not None:

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
from setuptools import setup, find_packages
44
from glob import glob
55

6-
__version__ = load_source('pystac.version', 'pystac/version.py').__version__
6+
__version__ = load_source('pystac.version', 'pystac/version.py').__version__ # type: ignore
77

88
from os.path import (
99
basename,

tests/extensions/test_custom.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ def apply(self, test_prop: Optional[str]) -> None:
3434

3535
@property
3636
def test_prop(self) -> Optional[str]:
37-
self._get_property(TEST_PROP, str)
37+
return self._get_property(TEST_PROP, str)
3838

3939
@test_prop.setter
4040
def test_prop(self, v: Optional[str]) -> None:

tests/extensions/test_pointcloud.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -122,9 +122,9 @@ def test_statistics(self) -> None:
122122

123123
# Get
124124
self.assertIn("pc:statistics", pc_item.properties)
125-
pc_statistics = [
126-
s.to_dict() for s in PointcloudExtension.ext(pc_item).statistics
127-
]
125+
statistics = PointcloudExtension.ext(pc_item).statistics
126+
assert statistics is not None
127+
pc_statistics = [s.to_dict() for s in statistics]
128128
self.assertEqual(pc_statistics, pc_item.properties["pc:statistics"])
129129

130130
# Set

tests/extensions/test_projection.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,7 @@ def test_epsg(self) -> None:
119119
self.assertEqual(proj_epsg, proj_item.properties["proj:epsg"])
120120

121121
# Set
122+
assert proj_epsg is not None
122123
ProjectionExtension.ext(proj_item).epsg = proj_epsg + 100
123124
self.assertEqual(proj_epsg + 100, proj_item.properties["proj:epsg"])
124125

@@ -196,9 +197,9 @@ def test_projjson(self) -> None:
196197
ProjectionExtension.ext(asset_no_prop).projjson,
197198
ProjectionExtension.ext(proj_item).projjson,
198199
)
199-
self.assertEqual(
200-
ProjectionExtension.ext(asset_prop).projjson["id"]["code"], 9999
201-
)
200+
asset_prop_json = ProjectionExtension.ext(asset_prop).projjson
201+
assert asset_prop_json is not None
202+
self.assertEqual(asset_prop_json["id"]["code"], 9999)
202203

203204
# Set to Asset
204205
asset_value = deepcopy(PROJJSON)
@@ -208,9 +209,9 @@ def test_projjson(self) -> None:
208209
ProjectionExtension.ext(asset_no_prop).projjson,
209210
ProjectionExtension.ext(proj_item).projjson,
210211
)
211-
self.assertEqual(
212-
ProjectionExtension.ext(asset_no_prop).projjson["id"]["code"], 7777
213-
)
212+
asset_no_prop_json = ProjectionExtension.ext(asset_no_prop).projjson
213+
assert asset_no_prop_json is not None
214+
self.assertEqual(asset_no_prop_json["id"]["code"], 7777)
214215

215216
# Validate
216217
proj_item.validate()
@@ -239,10 +240,9 @@ def test_geometry(self) -> None:
239240
ProjectionExtension.ext(asset_no_prop).geometry,
240241
ProjectionExtension.ext(proj_item).geometry,
241242
)
242-
self.assertEqual(
243-
ProjectionExtension.ext(asset_prop).geometry["coordinates"][0][0],
244-
[0.0, 0.0],
245-
)
243+
asset_prop_geometry = ProjectionExtension.ext(asset_prop).geometry
244+
assert asset_prop_geometry is not None
245+
self.assertEqual(asset_prop_geometry["coordinates"][0][0], [0.0, 0.0])
246246

247247
# Set to Asset
248248
asset_value: Dict[str, Any] = {"type": "Point", "coordinates": [1.0, 2.0]}

tests/extensions/test_scientific.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import datetime
44
import unittest
5+
from typing import List, Optional
56

67
import pystac
78
from pystac.extensions import scientific
@@ -183,7 +184,8 @@ def make_collection() -> pystac.Collection:
183184
end = start + datetime.timedelta(5, 4, 3, 2, 1)
184185
bboxes = [[-180.0, -90.0, 180.0, 90.0]]
185186
spatial_extent = pystac.SpatialExtent(bboxes)
186-
temporal_extent = pystac.TemporalExtent([[start, end]])
187+
intervals: List[List[Optional[datetime.datetime]]] = [[start, end]]
188+
temporal_extent = pystac.TemporalExtent(intervals)
187189
extent = pystac.Extent(spatial_extent, temporal_extent)
188190
collection = pystac.Collection(asset_id, "desc", extent)
189191
collection.set_self_href(URL_TEMPLATE % 2019)

tests/extensions/test_version.py

Lines changed: 33 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import datetime
44
import unittest
5+
from typing import List, Optional
56

67
import pystac
78
from pystac.extensions import version
@@ -134,17 +135,25 @@ def test_full_copy(self) -> None:
134135

135136
# Retrieve the copied version of the items
136137
item1_copy = cat_copy.get_item("area-1-1-imagery", recursive=True)
138+
assert item1_copy is not None
137139
item2_copy = cat_copy.get_item("area-2-2-imagery", recursive=True)
140+
assert item2_copy is not None
138141

139142
# Check to see if the version links point to the instances of the
140143
# item objects as they should.
141-
predecessor = item1_copy.get_single_link(version.PREDECESSOR).target
142-
successor = item2_copy.get_single_link(version.SUCCESSOR).target
143-
latest = item2_copy.get_single_link(version.LATEST).target
144-
145-
self.assertIs(predecessor, item2_copy)
146-
self.assertIs(successor, item1_copy)
147-
self.assertIs(latest, item1_copy)
144+
predecessor = item1_copy.get_single_link(version.PREDECESSOR)
145+
assert predecessor is not None
146+
predecessor_target = predecessor.target
147+
successor = item2_copy.get_single_link(version.SUCCESSOR)
148+
assert successor is not None
149+
successor_target = successor.target
150+
latest = item2_copy.get_single_link(version.LATEST)
151+
assert latest is not None
152+
latest_target = latest.target
153+
154+
self.assertIs(predecessor_target, item2_copy)
155+
self.assertIs(successor_target, item1_copy)
156+
self.assertIs(latest_target, item1_copy)
148157

149158
def test_setting_none_clears_link(self) -> None:
150159
deprecated = False
@@ -210,7 +219,8 @@ def make_collection(year: int) -> pystac.Collection:
210219
end = datetime.datetime(year, 1, 3, 4, 5)
211220
bboxes = [[-180.0, -90.0, 180.0, 90.0]]
212221
spatial_extent = pystac.SpatialExtent(bboxes)
213-
temporal_extent = pystac.TemporalExtent([[start, end]])
222+
intervals: List[List[Optional[datetime.datetime]]] = [[start, end]]
223+
temporal_extent = pystac.TemporalExtent(intervals)
214224
extent = pystac.Extent(spatial_extent, temporal_extent)
215225

216226
collection = pystac.Collection(asset_id, "desc", extent)
@@ -330,17 +340,25 @@ def test_full_copy(self) -> None:
330340

331341
# Retrieve the copied version of the items
332342
col1_copy = cat_copy.get_child("area-1-1", recursive=True)
343+
assert col1_copy is not None
333344
col2_copy = cat_copy.get_child("area-2-2", recursive=True)
345+
assert col2_copy is not None
334346

335347
# Check to see if the version links point to the instances of the
336348
# col objects as they should.
337-
predecessor = col1_copy.get_single_link(version.PREDECESSOR).target
338-
successor = col2_copy.get_single_link(version.SUCCESSOR).target
339-
latest = col2_copy.get_single_link(version.LATEST).target
340-
341-
self.assertIs(predecessor, col2_copy)
342-
self.assertIs(successor, col1_copy)
343-
self.assertIs(latest, col1_copy)
349+
predecessor = col1_copy.get_single_link(version.PREDECESSOR)
350+
assert predecessor is not None
351+
predecessor_target = predecessor.target
352+
successor = col2_copy.get_single_link(version.SUCCESSOR)
353+
assert successor is not None
354+
successor_target = successor.target
355+
latest = col2_copy.get_single_link(version.LATEST)
356+
assert latest is not None
357+
latest_target = latest.target
358+
359+
self.assertIs(predecessor_target, col2_copy)
360+
self.assertIs(successor_target, col1_copy)
361+
self.assertIs(latest_target, col1_copy)
344362

345363
def test_setting_none_clears_link(self) -> None:
346364
deprecated = False

tests/extensions/test_view.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ def test_off_nadir(self) -> None:
4646
# Get
4747
self.assertIn("view:off_nadir", view_item.properties)
4848
view_off_nadir = ViewExtension.ext(view_item).off_nadir
49+
assert view_off_nadir is not None
4950
self.assertEqual(view_off_nadir, view_item.properties["view:off_nadir"])
5051

5152
# Set
@@ -79,6 +80,7 @@ def test_incidence_angle(self) -> None:
7980
# Get
8081
self.assertIn("view:incidence_angle", view_item.properties)
8182
view_incidence_angle = ViewExtension.ext(view_item).incidence_angle
83+
assert view_incidence_angle is not None
8284
self.assertEqual(
8385
view_incidence_angle, view_item.properties["view:incidence_angle"]
8486
)
@@ -116,6 +118,7 @@ def test_azimuth(self) -> None:
116118
# Get
117119
self.assertIn("view:azimuth", view_item.properties)
118120
view_azimuth = ViewExtension.ext(view_item).azimuth
121+
assert view_azimuth is not None
119122
self.assertEqual(view_azimuth, view_item.properties["view:azimuth"])
120123

121124
# Set
@@ -149,6 +152,7 @@ def test_sun_azimuth(self) -> None:
149152
# Get
150153
self.assertIn("view:sun_azimuth", view_item.properties)
151154
view_sun_azimuth = ViewExtension.ext(view_item).sun_azimuth
155+
assert view_sun_azimuth is not None
152156
self.assertEqual(view_sun_azimuth, view_item.properties["view:sun_azimuth"])
153157

154158
# Set
@@ -184,6 +188,7 @@ def test_sun_elevation(self) -> None:
184188
# Get
185189
self.assertIn("view:sun_elevation", view_item.properties)
186190
view_sun_elevation = ViewExtension.ext(view_item).sun_elevation
191+
assert view_sun_elevation is not None
187192
self.assertEqual(view_sun_elevation, view_item.properties["view:sun_elevation"])
188193

189194
# Set

tests/serialization/test_identify.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ def test_version_ordering(self) -> None:
5959
self.assertFalse(STACVersionID("0.9.0") > "0.9.0") # type:ignore
6060
self.assertTrue(STACVersionID("0.9.0") <= "0.9.0") # type:ignore
6161
self.assertTrue(
62-
STACVersionID("1.0.0-beta.1")
62+
STACVersionID("1.0.0-beta.1") # type:ignore
6363
<= STACVersionID("1.0.0-beta.2") # type:ignore
6464
)
6565
self.assertFalse(STACVersionID("1.0.0") < STACVersionID("1.0.0-beta.2"))

tests/test_cache.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ def create_catalog(suffix: Any, include_href: bool = True) -> pystac.Catalog:
2020

2121

2222
class ResolvedObjectCacheTest(unittest.TestCase):
23-
def tests_get_or_cache_returns_previously_cached_href(self):
23+
def tests_get_or_cache_returns_previously_cached_href(self) -> None:
2424
cache = ResolvedObjectCache()
2525
cat = create_catalog(1)
2626
cache_result_1 = cache.get_or_cache(cat)

0 commit comments

Comments
 (0)