Skip to content

Commit 8d3b380

Browse files
committed
improve typing
1 parent 1d49423 commit 8d3b380

File tree

12 files changed

+60
-63
lines changed

12 files changed

+60
-63
lines changed

stac_fastapi/api/stac_fastapi/api/middleware.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ async def __call__(self, scope: Scope, receive: Receive, send: Send) -> None:
8282

8383
await self.app(scope, receive, send)
8484

85-
def _get_forwarded_url_parts(self, scope: Scope) -> Tuple[str]:
85+
def _get_forwarded_url_parts(self, scope: Scope) -> Tuple[str, str, str]:
8686
proto = scope.get("scheme", "http")
8787
header_host = self._get_header_value_by_name(scope, "host")
8888
if header_host is None:
@@ -127,7 +127,7 @@ def _get_header_value_by_name(
127127
@staticmethod
128128
def _replace_header_value_by_name(
129129
scope: Scope, header_name: str, new_value: str
130-
) -> List[Tuple[str]]:
130+
) -> List[Tuple[str, str]]:
131131
return [
132132
(name, value)
133133
for name, value in scope["headers"]

stac_fastapi/extensions/stac_fastapi/extensions/core/aggregation/types.py

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2,33 +2,34 @@
22

33
from typing import Any, Dict, List, Literal, Optional, Union
44

5-
from pydantic import Field
6-
from typing_extensions import TypedDict
5+
from typing_extensions import NotRequired, TypedDict
76

87
from stac_fastapi.types.rfc3339 import DateTimeType
98

9+
Bucket = TypedDict(
10+
"Bucket",
11+
{
12+
"key": str,
13+
"data_type": str,
14+
"frequency": NotRequired[Dict],
15+
# we can't use the `class Bucket` notation because `from` is a reserved key
16+
"from": NotRequired[Union[int, float]],
17+
"to": NotRequired[Optional[Union[int, float]]],
18+
},
19+
)
1020

11-
class Bucket(TypedDict, total=False):
12-
"""A STAC aggregation bucket."""
1321

14-
key: str
15-
data_type: str
16-
frequency: Optional[Dict] = None
17-
_from: Optional[Union[int, float]] = Field(alias="from", default=None)
18-
to: Optional[Optional[Union[int, float]]] = None
19-
20-
21-
class Aggregation(TypedDict, total=False):
22+
class Aggregation(TypedDict):
2223
"""A STAC aggregation."""
2324

2425
name: str
2526
data_type: str
26-
buckets: Optional[List[Bucket]] = None
27-
overflow: Optional[int] = None
28-
value: Optional[Union[str, int, DateTimeType]] = None
27+
buckets: NotRequired[List[Bucket]]
28+
overflow: NotRequired[int]
29+
value: NotRequired[Union[str, int, DateTimeType]]
2930

3031

31-
class AggregationCollection(TypedDict, total=False):
32+
class AggregationCollection(TypedDict):
3233
"""STAC Item Aggregation Collection."""
3334

3435
type: Literal["AggregationCollection"]

stac_fastapi/extensions/stac_fastapi/extensions/core/collection_search/request.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,15 +37,15 @@ class BaseCollectionSearchGetRequest(APIRequest, DatetimeMixin):
3737
class BaseCollectionSearchPostRequest(BaseModel):
3838
"""Collection-Search POST model."""
3939

40-
bbox: Optional[BBox] = Field(
40+
bbox: Optional[BBox] = Field( # type: ignore
4141
default=None,
4242
description="Only return items intersecting this bounding box. Mutually exclusive with **intersects**.", # noqa: E501
4343
openapi_examples={
4444
"user-provided": {"value": None},
4545
"Montreal": {"value": "-73.896103,45.364690,-73.413734,45.674283"},
4646
},
4747
)
48-
datetime: Optional[str] = Field(
48+
datetime: Optional[str] = Field( # type: ignore
4949
default=None,
5050
description="""Only return items that have a temporal property that intersects this value.\n
5151
Either a date-time or an interval, open or closed. Date and time expressions adhere to RFC 3339. Open intervals are expressed using double-dots.""", # noqa: E501

stac_fastapi/extensions/stac_fastapi/extensions/core/filter/request.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ class FilterExtensionGetRequest(APIRequest):
5050
class FilterExtensionPostRequest(BaseModel):
5151
"""Filter extension POST request model."""
5252

53-
filter_expr: Optional[Dict[str, Any]] = Field(
53+
filter_expr: Optional[Dict[str, Any]] = Field( # type: ignore
5454
default=None,
5555
alias="filter",
5656
description="A CQL filter expression for filtering items.",

stac_fastapi/extensions/stac_fastapi/extensions/core/free_text/request.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
from pydantic import BaseModel, Field
88
from typing_extensions import Annotated
99

10-
from stac_fastapi.types.search import APIRequest, str2list
10+
from stac_fastapi.types.search import APIRequest
1111

1212

1313
def _ft_converter(
@@ -22,7 +22,9 @@ def _ft_converter(
2222
),
2323
] = None,
2424
) -> Optional[List[str]]:
25-
return str2list(val)
25+
if val:
26+
return val.split(",")
27+
return None
2628

2729

2830
@attr.s

stac_fastapi/extensions/stac_fastapi/extensions/core/query/request.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ class QueryExtensionGetRequest(APIRequest):
2929
class QueryExtensionPostRequest(BaseModel):
3030
"""Query Extension POST request model."""
3131

32-
query: Optional[Dict[str, Dict[str, Any]]] = Field(
32+
query: Optional[Dict[str, Dict[str, Any]]] = Field( # type: ignore
3333
None,
3434
description="Allows additional filtering based on the properties of Item objects", # noqa: E501
3535
openapi_examples={

stac_fastapi/extensions/stac_fastapi/extensions/core/sort/request.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ class SortExtensionGetRequest(APIRequest):
3737
class SortExtensionPostRequest(BaseModel):
3838
"""Sortby parameter for POST requests."""
3939

40-
sortby: Optional[List[PostSortModel]] = Field(
40+
sortby: Optional[List[PostSortModel]] = Field( # type: ignore
4141
None,
4242
description="An array of property (field) names, and direction in form of '{'field': '<property_name>', 'direction':'<direction>'}'", # noqa: E501
4343
openapi_examples={

stac_fastapi/types/stac_fastapi/types/core.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -533,7 +533,7 @@ def item_collection(
533533
bbox: Optional[BBox] = None,
534534
datetime: Optional[str] = None,
535535
limit: int = 10,
536-
token: str = None,
536+
token: Optional[str] = None,
537537
**kwargs,
538538
) -> stac.ItemCollection:
539539
"""Get all items from a specific collection.
@@ -744,7 +744,7 @@ async def item_collection(
744744
bbox: Optional[BBox] = None,
745745
datetime: Optional[str] = None,
746746
limit: int = 10,
747-
token: str = None,
747+
token: Optional[str] = None,
748748
**kwargs,
749749
) -> stac.ItemCollection:
750750
"""Get all items from a specific collection.

stac_fastapi/types/stac_fastapi/types/extension.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ class ApiExtension(abc.ABC):
1515
GET = None
1616
POST = None
1717

18-
def get_request_model(self, verb: Optional[str] = "GET") -> Optional[BaseModel]:
18+
def get_request_model(self, verb: str = "GET") -> Optional[BaseModel]:
1919
"""Return the request model for the extension.method.
2020
2121
The model can differ based on HTTP verb

stac_fastapi/types/stac_fastapi/types/rfc3339.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ def str_to_interval(interval: Optional[str]) -> Optional[DateTimeType]:
145145
status_code=400, detail="Start datetime cannot be before end datetime."
146146
)
147147

148-
return start, end
148+
return start, end # type: ignore
149149

150150

151151
def now_in_utc() -> datetime:

0 commit comments

Comments
 (0)