|
1 | 1 | """Item crud client.""" |
| 2 | + |
2 | 3 | import re |
3 | 4 | from typing import Any, Dict, List, Optional, Union |
4 | 5 | from urllib.parse import unquote_plus, urljoin |
@@ -136,7 +137,7 @@ async def _get_base_item( |
136 | 137 |
|
137 | 138 | return item |
138 | 139 |
|
139 | | - async def _search_base( |
| 140 | + async def _search_base( # noqa: C901 |
140 | 141 | self, |
141 | 142 | search_request: PgstacSearch, |
142 | 143 | request: Request, |
@@ -172,10 +173,10 @@ async def _search_base( |
172 | 173 | req=search_request_json, |
173 | 174 | ) |
174 | 175 | items = await conn.fetchval(q, *p) |
175 | | - except InvalidDatetimeFormatError: |
| 176 | + except InvalidDatetimeFormatError as e: |
176 | 177 | raise InvalidQueryParameter( |
177 | 178 | f"Datetime parameter {search_request.datetime} is invalid." |
178 | | - ) |
| 179 | + ) from e |
179 | 180 |
|
180 | 181 | next: Optional[str] = items.pop("next", None) |
181 | 182 | prev: Optional[str] = items.pop("prev", None) |
@@ -207,8 +208,8 @@ async def _add_item_links( |
207 | 208 | and all([collection_id, item_id]) |
208 | 209 | ): |
209 | 210 | feature["links"] = await ItemLinks( |
210 | | - collection_id=collection_id, |
211 | | - item_id=item_id, |
| 211 | + collection_id=collection_id, # type: ignore |
| 212 | + item_id=item_id, # type: ignore |
212 | 213 | request=request, |
213 | 214 | ).get_links(extra_links=feature.get("links")) |
214 | 215 |
|
@@ -255,7 +256,7 @@ async def item_collection( |
255 | 256 | bbox: Optional[BBox] = None, |
256 | 257 | datetime: Optional[DateTimeType] = None, |
257 | 258 | limit: Optional[int] = None, |
258 | | - token: str = None, |
| 259 | + token: Optional[str] = None, |
259 | 260 | **kwargs, |
260 | 261 | ) -> ItemCollection: |
261 | 262 | """Get all items from a specific collection. |
@@ -340,7 +341,7 @@ async def post_search( |
340 | 341 | item_collection = await self._search_base(search_request, request=request) |
341 | 342 | return ItemCollection(**item_collection) |
342 | 343 |
|
343 | | - async def get_search( |
| 344 | + async def get_search( # noqa: C901 |
344 | 345 | self, |
345 | 346 | request: Request, |
346 | 347 | collections: Optional[List[str]] = None, |
@@ -432,5 +433,6 @@ async def get_search( |
432 | 433 | except ValidationError as e: |
433 | 434 | raise HTTPException( |
434 | 435 | status_code=400, detail=f"Invalid parameters provided {e}" |
435 | | - ) |
| 436 | + ) from e |
| 437 | + |
436 | 438 | return await self.post_search(search_request, request=request) |
0 commit comments