Skip to content

Commit 9293326

Browse files
committed
feat: Treat unused ignores as an error
1 parent 24bcca6 commit 9293326

File tree

10 files changed

+42
-37
lines changed

10 files changed

+42
-37
lines changed

mypy.ini

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,4 @@ no_implicit_optional = True
66
show_error_codes = True
77
warn_redundant_casts = True
88
warn_return_any = True
9+
warn_unused_ignores = True

pystac/__init__.py

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -4,36 +4,36 @@
44

55
# flake8: noqa
66
from pystac.errors import (
7-
STACError, # type:ignore
8-
STACTypeError, # type:ignore
9-
ExtensionAlreadyExistsError, # type:ignore
10-
ExtensionTypeError, # type:ignore
11-
RequiredPropertyMissing, # type:ignore
12-
STACValidationError, # type:ignore
7+
STACError,
8+
STACTypeError,
9+
ExtensionAlreadyExistsError,
10+
ExtensionTypeError,
11+
RequiredPropertyMissing,
12+
STACValidationError,
1313
)
1414

1515
from typing import Any, Dict, Optional
1616
from pystac.version import (
1717
__version__,
18-
get_stac_version, # type:ignore
19-
set_stac_version, # type:ignore
18+
get_stac_version,
19+
set_stac_version,
2020
)
21-
from pystac.media_type import MediaType # type:ignore
22-
from pystac.rel_type import RelType # type: ignore
23-
from pystac.stac_io import StacIO # type:ignore
24-
from pystac.stac_object import STACObject, STACObjectType # type:ignore
25-
from pystac.link import Link, HIERARCHICAL_LINKS # type:ignore
26-
from pystac.catalog import Catalog, CatalogType # type:ignore
21+
from pystac.media_type import MediaType
22+
from pystac.rel_type import RelType
23+
from pystac.stac_io import StacIO
24+
from pystac.stac_object import STACObject, STACObjectType
25+
from pystac.link import Link, HIERARCHICAL_LINKS
26+
from pystac.catalog import Catalog, CatalogType
2727
from pystac.collection import (
28-
Collection, # type:ignore
29-
Extent, # type:ignore
30-
SpatialExtent, # type:ignore
31-
TemporalExtent, # type:ignore
32-
Provider, # type:ignore
33-
Summaries, # type:ignore
28+
Collection,
29+
Extent,
30+
SpatialExtent,
31+
TemporalExtent,
32+
Provider,
33+
Summaries,
3434
)
35-
from pystac.summaries import RangeSummary # type:ignore
36-
from pystac.item import Item, Asset, CommonMetadata # type:ignore
35+
from pystac.summaries import RangeSummary
36+
from pystac.item import Item, Asset, CommonMetadata
3737

3838
import pystac.validation
3939

pystac/serialization/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
import pystac
55
from pystac.serialization.identify import (
6-
STACVersionRange, # type:ignore
6+
STACVersionRange,
77
identify_stac_object,
88
identify_stac_object_type,
99
)

pystac/stac_io.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323

2424
# Use orjson if available
2525
try:
26-
import orjson # type: ignore
26+
import orjson
2727
except ImportError:
2828
orjson = None # type: ignore[assignment]
2929

pystac/stac_object.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ def validate(self) -> List[Any]:
5656
"""
5757
import pystac.validation
5858

59-
return pystac.validation.validate(self) # type:ignore
59+
return pystac.validation.validate(self)
6060

6161
def add_link(self, link: Link) -> None:
6262
"""Add a link to this object's set of links.

pystac/utils.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -194,8 +194,14 @@ def extract_coords(coords: List[Union[List[float], List[List[Any]]]]) -> None:
194194
for x in coords:
195195
# This handles points
196196
if isinstance(x, float):
197-
lats.append(coords[0]) # type:ignore
198-
lons.append(coords[1]) # type:ignore
197+
assert isinstance(
198+
coords[0], float
199+
), f"Type mismatch: {coords[0]} is not a float"
200+
assert isinstance(
201+
coords[1], float
202+
), f"Type mismatch: {coords[1]} is not a float"
203+
lats.append(coords[0])
204+
lons.append(coords[1])
199205
return
200206
if isinstance(x[0], list):
201207
extract_coords(x) # type:ignore

pystac/validation/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ class RegisteredValidator:
162162
def get_validator(cls) -> STACValidator:
163163
if cls._validator is None:
164164
try:
165-
import jsonschema # type:ignore
165+
import jsonschema
166166
except ImportError:
167167
raise Exception(
168168
'Cannot validate with default validator because package "jsonschema" '

pystac/validation/stac_validator.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -157,9 +157,7 @@ def get_schema_from_uri(self, schema_uri: str) -> Tuple[Dict[str, Any], Any]:
157157

158158
def _validate_from_uri(self, stac_dict: Dict[str, Any], schema_uri: str) -> None:
159159
schema, resolver = self.get_schema_from_uri(schema_uri)
160-
jsonschema.validate(
161-
instance=stac_dict, schema=schema, resolver=resolver
162-
) # type:ignore
160+
jsonschema.validate(instance=stac_dict, schema=schema, resolver=resolver)
163161
for uri in resolver.store:
164162
if uri not in self.schema_cache:
165163
self.schema_cache[uri] = resolver.store[uri]

tests/serialization/test_identify.py

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

tests/utils/__init__.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,18 @@
33
from typing import Any, Dict, Type
44
import unittest
55
from tests.utils.test_cases import (
6-
TestCases, # type:ignore
7-
ARBITRARY_GEOM, # type:ignore
8-
ARBITRARY_BBOX, # type:ignore
9-
ARBITRARY_EXTENT, # type:ignore
6+
TestCases,
7+
ARBITRARY_GEOM,
8+
ARBITRARY_BBOX,
9+
ARBITRARY_EXTENT,
1010
)
1111

1212
from copy import deepcopy
1313
from datetime import datetime
1414
from dateutil.parser import parse
1515

1616
import pystac
17-
from tests.utils.stac_io_mock import MockStacIO # type:ignore
17+
from tests.utils.stac_io_mock import MockStacIO
1818

1919

2020
def assert_to_from_dict(

0 commit comments

Comments
 (0)