Skip to content
This repository was archived by the owner on Apr 2, 2025. It is now read-only.

Commit 7e36a03

Browse files
author
Phil Varner
committed
enable mypy, and fix code warnings produced by it
1 parent a83d93c commit 7e36a03

File tree

7 files changed

+21
-11
lines changed

7 files changed

+21
-11
lines changed

.pre-commit-config.yaml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,10 @@ repos:
1515
- id: ruff
1616
args: [--fix, --exit-non-zero-on-fix]
1717
- id: ruff-format
18+
- repo: https://github.com/pre-commit/mirrors-mypy
19+
rev: v1.13.0
20+
hooks:
21+
- id: mypy
22+
files: ".*\\.py$"
23+
additional_dependencies:
24+
- types-pyRFC3339~=1.1.1

bin/server.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,14 @@
33
from fastapi import FastAPI, Request
44

55
from stapi_fastapi.backends.product_backend import ProductBackend
6+
from stapi_fastapi.backends.root_backend import RootBackend
67
from stapi_fastapi.exceptions import ConstraintsException, NotFoundException
78
from stapi_fastapi.models.opportunity import (
89
Opportunity,
910
OpportunityPropertiesBase,
1011
OpportunityRequest,
1112
)
12-
from stapi_fastapi.models.order import Order
13+
from stapi_fastapi.models.order import Order, OrderCollection
1314
from stapi_fastapi.models.product import (
1415
Product,
1516
Provider,
@@ -22,15 +23,15 @@ class MockOrderDB(dict[int | str, Order]):
2223
pass
2324

2425

25-
class MockRootBackend:
26+
class MockRootBackend(RootBackend):
2627
def __init__(self, orders: MockOrderDB) -> None:
2728
self._orders: MockOrderDB = orders
2829

29-
async def get_orders(self, request: Request) -> list[Order]:
30+
async def get_orders(self, request: Request) -> OrderCollection:
3031
"""
3132
Show all orders.
3233
"""
33-
return list(self._orders.values())
34+
return OrderCollection(features=list(self._orders.values()))
3435

3536
async def get_order(self, order_id: str, request: Request) -> Order:
3637
"""

src/stapi_fastapi/exceptions.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from typing import Any
1+
from typing import Any, Optional
22

33
from fastapi import HTTPException, status
44

@@ -13,5 +13,5 @@ def __init__(self, detail: Any) -> None:
1313

1414

1515
class NotFoundException(StapiException):
16-
def __init__(self, detail: Any) -> None:
16+
def __init__(self, detail: Optional[Any] = None) -> None:
1717
super().__init__(status.HTTP_404_NOT_FOUND, detail)

src/stapi_fastapi/models/order.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ class OrderProperties(BaseModel):
1616
class Order(Feature[Geometry, OrderProperties]):
1717
# We need to enforce that orders have an id defined, as that is required to
1818
# retrieve them via the API
19-
id: StrictInt | StrictStr # type: ignore
19+
id: StrictInt | StrictStr
2020
type: Literal["Feature"] = "Feature"
2121
links: list[Link] = Field(default_factory=list)
2222

src/stapi_fastapi/routers/product_router.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,8 @@ def __init__(
4747
name=f"{self.root_router.name}:{self.product.id}:search-opportunities",
4848
methods=["POST"],
4949
response_class=GeoJSONResponse,
50-
response_model=OpportunityCollection[Geometry, self.product.constraints],
50+
# unknown why mypy can't see the constraints property on Product, ignoring
51+
response_model=OpportunityCollection[Geometry, self.product.constraints], # type: ignore
5152
summary="Search Opportunities for the product",
5253
)
5354

tests/backends.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
from fastapi import Request
44

55
from stapi_fastapi.backends.product_backend import ProductBackend
6+
from stapi_fastapi.backends.root_backend import RootBackend
67
from stapi_fastapi.exceptions import ConstraintsException, NotFoundException
78
from stapi_fastapi.models.opportunity import Opportunity, OpportunityRequest
89
from stapi_fastapi.models.order import Order, OrderCollection
@@ -13,15 +14,15 @@ class MockOrderDB(dict[int | str, Order]):
1314
pass
1415

1516

16-
class MockRootBackend:
17+
class MockRootBackend(RootBackend):
1718
def __init__(self, orders: MockOrderDB) -> None:
1819
self._orders = orders
1920

2021
async def get_orders(self, request: Request) -> OrderCollection:
2122
"""
2223
Show all orders.
2324
"""
24-
return list(self._orders.values())
25+
return OrderCollection(features=list(self._orders.values()))
2526

2627
async def get_order(self, order_id: str, request: Request) -> Order:
2728
"""

tests/datetime_interval_test.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ class Model(BaseModel):
1616

1717

1818
def rfc3339_strftime(dt: datetime, format: str) -> str:
19-
tds = timedelta_seconds(dt.tzinfo.utcoffset(dt))
19+
tds = timedelta_seconds(dt.tzinfo.utcoffset(dt)) # type: ignore
2020
long = timezone(tds)
2121
short = "Z"
2222

0 commit comments

Comments
 (0)