Skip to content

Commit 3b53c80

Browse files
committed
apply ruff linting/format & make mypy happy
1 parent 5bdd317 commit 3b53c80

25 files changed

+141
-278
lines changed

stapi-fastapi/src/stapi_fastapi/backends/product_backend.py

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
from __future__ import annotations
22

3-
from collections.abc import Coroutine
4-
from typing import Any, Callable
3+
from collections.abc import Callable, Coroutine
4+
from typing import Any
55

66
from fastapi import Request
77
from returns.maybe import Maybe
@@ -18,7 +18,7 @@
1818

1919
SearchOpportunities = Callable[
2020
[ProductRouter, OpportunityPayload, str | None, int, Request],
21-
Coroutine[Any, Any, ResultE[tuple[list[Opportunity], Maybe[str]]]],
21+
Coroutine[Any, Any, ResultE[tuple[list[Opportunity], Maybe[str]]]], # type: ignore
2222
]
2323
"""
2424
Type alias for an async function that searches for ordering opportunities for the given
@@ -34,8 +34,10 @@
3434
Returns:
3535
A tuple containing a list of opportunities and a pagination token.
3636
37-
- Should return returns.result.Success[tuple[list[Opportunity], returns.maybe.Some[str]]] if including a pagination token
38-
- Should return returns.result.Success[tuple[list[Opportunity], returns.maybe.Nothing]] if not including a pagination token
37+
- Should return returns.result.Success[tuple[list[Opportunity], returns.maybe.Some[str]]]
38+
if including a pagination token
39+
- Should return returns.result.Success[tuple[list[Opportunity], returns.maybe.Nothing]]
40+
if not including a pagination token
3941
- Returning returns.result.Failure[Exception] will result in a 500.
4042
4143
Note:
@@ -66,7 +68,7 @@
6668

6769
GetOpportunityCollection = Callable[
6870
[ProductRouter, str, Request],
69-
Coroutine[Any, Any, ResultE[Maybe[OpportunityCollection]]],
71+
Coroutine[Any, Any, ResultE[Maybe[OpportunityCollection]]], # type: ignore
7072
]
7173
"""
7274
Type alias for an async function that retrieves the opportunity collection with
@@ -80,14 +82,14 @@
8082
request (Request): FastAPI's Request object.
8183
8284
Returns:
83-
- Should return returns.result.Success[returns.maybe.Some[OpportunityCollection]] if the opportunity collection is found.
84-
- Should return returns.result.Success[returns.maybe.Nothing] if the opportunity collection is not found or if access is denied.
85+
- Should return returns.result.Success[returns.maybe.Some[OpportunityCollection]]
86+
if the opportunity collection is found.
87+
- Should return returns.result.Success[returns.maybe.Nothing] if the opportunity collection is not found or
88+
if access is denied.
8589
- Returning returns.result.Failure[Exception] will result in a 500.
8690
"""
8791

88-
CreateOrder = Callable[
89-
[ProductRouter, OrderPayload, Request], Coroutine[Any, Any, ResultE[Order]]
90-
]
92+
CreateOrder = Callable[[ProductRouter, OrderPayload, Request], Coroutine[Any, Any, ResultE[Order]]] # type: ignore
9193
"""
9294
Type alias for an async function that creates a new order.
9395

stapi-fastapi/src/stapi_fastapi/backends/root_backend.py

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
from collections.abc import Coroutine
2-
from typing import Any, Callable, TypeVar
1+
from collections.abc import Callable, Coroutine
2+
from typing import Any, TypeVar
33

44
from fastapi import Request
55
from returns.maybe import Maybe
@@ -26,8 +26,10 @@
2626
Returns:
2727
A tuple containing a list of orders and a pagination token.
2828
29-
- Should return returns.result.Success[tuple[list[Order], returns.maybe.Some[str]]] if including a pagination token
30-
- Should return returns.result.Success[tuple[list[Order], returns.maybe.Nothing]] if not including a pagination token
29+
- Should return returns.result.Success[tuple[list[Order], returns.maybe.Some[str]]]
30+
if including a pagination token
31+
- Should return returns.result.Success[tuple[list[Order], returns.maybe.Nothing]]
32+
if not including a pagination token
3133
- Returning returns.result.Failure[Exception] will result in a 500.
3234
"""
3335

@@ -65,8 +67,10 @@
6567
Returns:
6668
A tuple containing a list of order statuses and a pagination token.
6769
68-
- Should return returns.result.Success[returns.maybe.Some[tuple[list[OrderStatus], returns.maybe.Some[str]]] if order is found and including a pagination token.
69-
- Should return returns.result.Success[returns.maybe.Some[tuple[list[OrderStatus], returns.maybe.Nothing]]] if order is found and not including a pagination token.
70+
- Should return returns.result.Success[returns.maybe.Some[tuple[list[OrderStatus], returns.maybe.Some[str]]]
71+
if order is found and including a pagination token.
72+
- Should return returns.result.Success[returns.maybe.Some[tuple[list[OrderStatus], returns.maybe.Nothing]]]
73+
if order is found and not including a pagination token.
7074
- Should return returns.result.Success[returns.maybe.Nothing] if the order is not found or if access is denied.
7175
- Returning returns.result.Failure[Exception] will result in a 500.
7276
"""
@@ -84,14 +88,14 @@
8488
limit (int): The maximum number of search records to return in a page.
8589
8690
Returns:
87-
- Should return returns.result.Success[tuple[list[OpportunitySearchRecord], returns.maybe.Some[str]]] if including a pagination token
88-
- Should return returns.result.Success[tuple[list[OpportunitySearchRecord], returns.maybe.Nothing]] if not including a pagination token
91+
- Should return returns.result.Success[tuple[list[OpportunitySearchRecord], returns.maybe.Some[str]]]
92+
if including a pagination token
93+
- Should return returns.result.Success[tuple[list[OpportunitySearchRecord], returns.maybe.Nothing]]
94+
if not including a pagination token
8995
- Returning returns.result.Failure[Exception] will result in a 500.
9096
"""
9197

92-
GetOpportunitySearchRecord = Callable[
93-
[str, Request], Coroutine[Any, Any, ResultE[Maybe[OpportunitySearchRecord]]]
94-
]
98+
GetOpportunitySearchRecord = Callable[[str, Request], Coroutine[Any, Any, ResultE[Maybe[OpportunitySearchRecord]]]]
9599
"""
96100
Type alias for an async function that gets the OpportunitySearchRecord with
97101
`search_record_id`.
@@ -102,6 +106,7 @@
102106
103107
Returns:
104108
- Should return returns.result.Success[returns.maybe.Some[OpportunitySearchRecord]] if the search record is found.
105-
- Should return returns.result.Success[returns.maybe.Nothing] if the search record is not found or if access is denied.
109+
- Should return returns.result.Success[returns.maybe.Nothing] if the search record is not found or
110+
if access is denied.
106111
- Returning returns.result.Failure[Exception] will result in a 500.
107112
"""

stapi-fastapi/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, Optional
1+
from typing import Any
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: Optional[Any] = None) -> None:
16+
def __init__(self, detail: Any | None = None) -> None:
1717
super().__init__(status.HTTP_404_NOT_FOUND, detail)

stapi-fastapi/src/stapi_fastapi/models/conformance.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,4 @@
66

77

88
class Conformance(BaseModel):
9-
conforms_to: list[str] = Field(
10-
default_factory=list, serialization_alias="conformsTo"
11-
)
9+
conforms_to: list[str] = Field(default_factory=list, serialization_alias="conformsTo")

stapi-fastapi/src/stapi_fastapi/models/order.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from collections.abc import Iterator
22
from enum import StrEnum
3-
from typing import Any, Generic, Literal, Optional, TypeVar, Union
3+
from typing import Any, Generic, Literal, TypeVar
44

55
from geojson_pydantic.base import _GeoJsonBase
66
from geojson_pydantic.geometries import Geometry
@@ -18,7 +18,7 @@
1818
from stapi_fastapi.types.datetime_interval import DatetimeInterval
1919
from stapi_fastapi.types.filter import CQL2Filter
2020

21-
Props = TypeVar("Props", bound=Union[dict[str, Any], BaseModel])
21+
Props = TypeVar("Props", bound=dict[str, Any] | BaseModel)
2222
Geom = TypeVar("Geom", bound=Geometry)
2323

2424

@@ -47,8 +47,8 @@ class OrderStatusCode(StrEnum):
4747
class OrderStatus(BaseModel):
4848
timestamp: AwareDatetime
4949
status_code: OrderStatusCode
50-
reason_code: Optional[str] = None
51-
reason_text: Optional[str] = None
50+
reason_code: str | None = None
51+
reason_text: str | None = None
5252
links: list[Link] = Field(default_factory=list)
5353

5454
model_config = ConfigDict(extra="allow")
@@ -86,7 +86,7 @@ class Order(_GeoJsonBase):
8686
type: Literal["Feature"] = "Feature"
8787

8888
geometry: Geometry = Field(...)
89-
properties: OrderProperties = Field(...)
89+
properties: OrderProperties[OrderStatus] = Field(...)
9090

9191
links: list[Link] = Field(default_factory=list)
9292

stapi-fastapi/src/stapi_fastapi/models/product.py

Lines changed: 9 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
from __future__ import annotations
22

33
from enum import StrEnum
4-
from typing import TYPE_CHECKING, Literal, Optional, Self
4+
from typing import TYPE_CHECKING, Any, Literal, Self
55

66
from pydantic import AnyHttpUrl, BaseModel, Field
77

@@ -30,13 +30,13 @@ class ProviderRole(StrEnum):
3030

3131
class Provider(BaseModel):
3232
name: str
33-
description: Optional[str] = None
33+
description: str | None = None
3434
roles: list[ProviderRole]
3535
url: AnyHttpUrl
3636

3737
# redefining init is a hack to get str type to validate for `url`,
3838
# as str is ultimately coerced into an AnyHttpUrl automatically anyway
39-
def __init__(self, url: AnyHttpUrl | str, **kwargs) -> None:
39+
def __init__(self, url: AnyHttpUrl | str, **kwargs: Any) -> None:
4040
super().__init__(url=url, **kwargs)
4141

4242

@@ -62,15 +62,15 @@ class Product(BaseModel):
6262

6363
def __init__(
6464
self,
65-
*args,
65+
*args: Any,
6666
constraints: type[Constraints],
6767
opportunity_properties: type[OpportunityProperties],
6868
order_parameters: type[OrderParameters],
6969
create_order: CreateOrder,
7070
search_opportunities: SearchOpportunities | None = None,
7171
search_opportunities_async: SearchOpportunitiesAsync | None = None,
7272
get_opportunity_collection: GetOpportunityCollection | None = None,
73-
**kwargs,
73+
**kwargs: Any,
7474
) -> None:
7575
super().__init__(*args, **kwargs)
7676

@@ -101,17 +101,13 @@ def search_opportunities(self) -> SearchOpportunities:
101101
@property
102102
def search_opportunities_async(self) -> SearchOpportunitiesAsync:
103103
if not self._search_opportunities_async:
104-
raise AttributeError(
105-
"This product does not support async opportunity search"
106-
)
104+
raise AttributeError("This product does not support async opportunity search")
107105
return self._search_opportunities_async
108106

109107
@property
110108
def get_opportunity_collection(self) -> GetOpportunityCollection:
111109
if not self._get_opportunity_collection:
112-
raise AttributeError(
113-
"This product does not support async opportunity search"
114-
)
110+
raise AttributeError("This product does not support async opportunity search")
115111
return self._get_opportunity_collection
116112

117113
@property
@@ -132,10 +128,7 @@ def supports_opportunity_search(self) -> bool:
132128

133129
@property
134130
def supports_async_opportunity_search(self) -> bool:
135-
return (
136-
self._search_opportunities_async is not None
137-
and self._get_opportunity_collection is not None
138-
)
131+
return self._search_opportunities_async is not None and self._get_opportunity_collection is not None
139132

140133
def with_links(self, links: list[Link] | None = None) -> Self:
141134
if not links:
@@ -147,8 +140,6 @@ def with_links(self, links: list[Link] | None = None) -> Self:
147140

148141

149142
class ProductsCollection(BaseModel):
150-
type_: Literal["ProductCollection"] = Field(
151-
default="ProductCollection", alias="type"
152-
)
143+
type_: Literal["ProductCollection"] = Field(default="ProductCollection", alias="type")
153144
links: list[Link] = Field(default_factory=list)
154145
products: list[Product]

stapi-fastapi/src/stapi_fastapi/models/shared.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ class Link(BaseModel):
2222

2323
# redefining init is a hack to get str type to validate for `href`,
2424
# as str is ultimately coerced into an AnyUrl automatically anyway
25-
def __init__(self, href: AnyUrl | str, **kwargs):
25+
def __init__(self, href: AnyUrl | str, **kwargs: Any) -> None:
2626
super().__init__(href=href, **kwargs)
2727

2828
# overriding the default serialization to filter None field values from

0 commit comments

Comments
 (0)