Skip to content

Commit bdd1169

Browse files
committed
Fix remaining mypy errors
1 parent f73dc24 commit bdd1169

File tree

12 files changed

+26
-28
lines changed

12 files changed

+26
-28
lines changed

.pre-commit-config.yaml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,5 @@ repos:
1616
rev: v0.910
1717
hooks:
1818
- id: mypy
19-
language_version: python
19+
language_version: python
20+
args: [--install-types, --non-interactive]

oaff/app/oaff/app/data/sources/postgresql/stac_hybrid/postgresql_data_source.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
from hashlib import sha256
33
from logging import getLogger
44
from os import path
5-
from typing import Any, Coroutine, Dict, Final, List, Type
5+
from typing import Any, Awaitable, Callable, Dict, Final, List, Type
66

77
# geoalchemy import required for sa.MetaData reflection, even though unused in module
88
import geoalchemy2 as ga # noqa: F401
@@ -51,7 +51,7 @@ class PostgresqlDataSource(DataSource):
5151
def __init__(
5252
self,
5353
connection_name: str,
54-
connection_tester: Coroutine[None, None, Database],
54+
connection_tester: Callable[[Database, str], Awaitable[None]],
5555
):
5656
super().__init__(f"{self.DATA_SOURCE_NAME}:{connection_name}")
5757
self.db = Database(settings.url(connection_name))
@@ -225,7 +225,7 @@ async def _get_derived_layers(self) -> Dict[str, PostgresqlLayer]:
225225
bboxes=[table_spatial_extents[qualified_layer_name]],
226226
intervals=table_temporal_extents[qualified_layer_name]
227227
if qualified_layer_name in table_temporal_extents
228-
else [[None, None]],
228+
else [[None, None]], # type: ignore
229229
data_source_id=self.id,
230230
schema_name=tables[qualified_layer_name]["schema_name"],
231231
table_name=tables[qualified_layer_name]["table_name"],

oaff/app/oaff/app/request_handlers/collection_items.py

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -130,14 +130,13 @@ async def _spatial_bounds_to_node(
130130
) -> BBox:
131131
# recommended usage for Union of types
132132
# https://github.com/python/mypy/issues/1178#issuecomment-176185607
133-
x_min, y_min, x_max, y_max = (
134-
cast(Tuple[float, float, float, float], spatial_bounds) # type: ignore
135-
if len(spatial_bounds) == 4
136-
else (
137-
cast(Tuple[float, float, float, float, float, float], spatial_bounds)[i]
138-
for i in [0, 1, 3, 4]
133+
if len(spatial_bounds) == 4:
134+
a, b, c, d = cast(Tuple[float, float, float, float], spatial_bounds)
135+
else:
136+
a, b, _, c, d, _ = cast(
137+
Tuple[float, float, float, float, float, float], spatial_bounds
139138
)
140-
)
139+
x_min, y_min, x_max, y_max = (a, b, c, d)
141140
transformer = Transformer.from_crs(
142141
"EPSG:4326", # True until Features API spec part 2 is implemented
143142
f"{layer.geometry_crs_auth_name}:{layer.geometry_crs_auth_code}",
@@ -336,6 +335,6 @@ def _match_query_time_to_end_field(
336335
)
337336

338337
def _match_query_time_to(
339-
self, query_time: datetime, tz_aware: bool, tz: Type[tzinfo]
338+
self, query_time: datetime, tz_aware: bool, tz: tzinfo
340339
) -> datetime:
341340
return query_time if tz_aware else query_time.astimezone(tz).replace(tzinfo=None)

oaff/app/oaff/app/request_handlers/collections_list.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
LOGGER: Final = getLogger(__file__)
1313

1414

15-
class CollectionsList(RequestHandler):
15+
class CollectionsList(RequestHandler): # type: ignore
1616
@classmethod
1717
def type_name(cls) -> str:
1818
return CollectionsList.__name__

oaff/app/oaff/app/request_handlers/conformance.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
from oaff.app.responses.response_format import ResponseFormat
88

99

10-
class Conformance(RequestHandler):
10+
class Conformance(RequestHandler): # type: ignore
1111
@classmethod
1212
def type_name(cls) -> str:
1313
return Conformance.__name__

oaff/app/oaff/app/request_handlers/landing_page.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
from oaff.app.settings import OPENAPI_OGC_TYPE
1313

1414

15-
class LandingPage(RequestHandler):
15+
class LandingPage(RequestHandler): # type: ignore
1616
@classmethod
1717
def type_name(cls) -> str:
1818
return LandingPage.__name__

oaff/app/oaff/app/responses/response_format.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
from oaff.app.responses.response_type import ResponseType
44

55

6-
class ResponseFormat(dict, Enum):
6+
class ResponseFormat(dict, Enum): # type: ignore
77
html = {
88
ResponseType.DATA: "text/html",
99
ResponseType.METADATA: "text/html",

oaff/app/oaff/app/responses/templates/templates.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ def get_rendered_html(template_name: str, data: object, locale: Locales) -> str:
1313
loader=PackageLoader("oaff.app", path.join("responses", "templates", "html")),
1414
autoescape=select_autoescape(["html"]),
1515
)
16-
env.install_gettext_translations(get_translations_for_locale(locale))
16+
env.install_gettext_translations(get_translations_for_locale(locale)) # type: ignore
1717
frontend_config = get_frontend_configuration()
1818
return env.get_template(f"{template_name}.jinja2").render(
1919
response=data,

oaff/fastapi/api/openapi/openapi.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
1+
from typing import Callable
2+
13
from fastapi.applications import FastAPI
24
from fastapi.requests import Request
35

46
from oaff.fastapi.api.openapi.vnd_response import VndResponse
57

68

7-
def get_openapi_handler(app: FastAPI) -> VndResponse:
9+
def get_openapi_handler(app: FastAPI) -> Callable[[Request], VndResponse]:
810
def handler(_: Request):
911
# OpenAPI spec must be modified because FastAPI doesn't support
1012
# encoding style: https://github.com/tiangolo/fastapi/issues/283

oaff/fastapi/api/routes/collections.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
11
from datetime import datetime
22
from logging import getLogger
3-
from typing import Final, Optional, Tuple, Union
3+
from typing import Final, Optional, Tuple, Union, cast
44
from urllib.parse import quote
55

66
import iso8601
77
import pytz
8-
from fastapi import APIRouter, HTTPException
8+
from fastapi import APIRouter, HTTPException, Query
99
from fastapi.param_functions import Depends
10-
from fastapi.params import Query
1110
from fastapi.requests import Request
1211

1312
from oaff.app.requests.collection import Collection as CollectionRequestType
@@ -216,7 +215,7 @@ def parse_datetime(datetime_str: str) -> datetime:
216215
raise HTTPException(
217216
status_code=400, detail="datetime start cannot be after end"
218217
)
219-
return tuple(result)
218+
return cast(Union[Tuple[datetime], Tuple[datetime, datetime]], tuple(result))
220219

221220

222221
def _get_safe_url(path_template: str, request: Request, root: str) -> str:

oaff/fastapi/api/routes/common/common_parameters.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
from re import compile, search, sub
2-
from typing import Final, Optional, Set
2+
from typing import Final, List, Optional
33

44
from fastapi import Header, Query
55
from fastapi.requests import Request
@@ -66,7 +66,7 @@ async def populate(
6666
)
6767

6868
@classmethod
69-
def _header_options_by_preference(cls, header_value: str) -> Set[str]:
69+
def _header_options_by_preference(cls, header_value: str) -> List[str]:
7070
options = list(
7171
filter(
7272
lambda option: len(option) > 0,
@@ -84,6 +84,4 @@ def _header_options_by_preference(cls, header_value: str) -> Set[str]:
8484
option_and_weight[0].strip(): option_and_weight[1].strip()
8585
for option_and_weight in [option.split(";q=") for option in weighted]
8686
}
87-
return set(
88-
unweighted + sorted(options_with_weight, key=options_with_weight.get)[::-1]
89-
)
87+
return unweighted + sorted(options_with_weight, key=options_with_weight.get)[::-1]

pyproject.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,5 @@ exclude="^(tests|testing)$"
3838
namespace_packages=true
3939
explicit_package_bases=true
4040
ignore_missing_imports=true
41-
ignore_errors=true
4241
no_warn_no_return=true
4342
no_strict_optional=true

0 commit comments

Comments
 (0)