Skip to content

Commit b484e6f

Browse files
committed
fix: typing errors
1 parent 77114f0 commit b484e6f

File tree

1 file changed

+24
-20
lines changed

1 file changed

+24
-20
lines changed

eodag/plugins/search/cop_ghsl.py

Lines changed: 24 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
from pyproj import CRS, Transformer
1010
from typing_extensions import get_args
1111

12-
from eodag.api.product._assets import Asset, AssetsDict
12+
from eodag.api.product._assets import AssetsDict
1313
from eodag.api.product._product import EOProduct
1414
from eodag.api.product.metadata_mapping import (
1515
mtd_cfg_as_conversion_and_querypath,
@@ -19,7 +19,7 @@
1919
from eodag.plugins.search.base import Search
2020
from eodag.types import json_field_definition_to_python
2121
from eodag.types.queryables import Queryables
22-
from eodag.utils import HTTP_REQ_TIMEOUT, deepcopy
22+
from eodag.utils import DEFAULT_ITEMS_PER_PAGE, HTTP_REQ_TIMEOUT, deepcopy
2323
from eodag.utils.cache import instance_cached_method
2424
from eodag.utils.exceptions import (
2525
MisconfiguredError,
@@ -76,13 +76,13 @@ def _get_available_values_from_constraints(
7676
constraints: list[dict[str, Any]], filters: dict[str, Any], product_type: str
7777
) -> dict[str, list[Any]]:
7878
"""get the available values for each parameter from the constraints"""
79-
available_values = {}
79+
available_values: dict[str, list[Any]] = {}
8080
constraint_keys = set([k for const in constraints for k in const.keys()])
8181
not_found_keys = set(filters.keys()) - constraint_keys
8282
if "month" in not_found_keys and isinstance(filters["month"], list):
8383
# month added from datetime but filter not available
8484
filters.pop("month")
85-
not_found_keys.pop("month")
85+
not_found_keys.remove("month")
8686
if not_found_keys and not_found_keys != {"id"}:
8787
raise ValidationError(
8888
f"Parameters {not_found_keys} do not exist for product type {product_type}; "
@@ -221,9 +221,9 @@ def _get_start_and_end_from_properties(
221221
second=59,
222222
)
223223
else:
224-
start_date = self.get_product_type_cfg_value("missionStartDate")
225-
end_date = self.get_product_type_cfg_value("missionEndDate")
226-
return {"start_date": start_date, "end_date": end_date}
224+
start_date_str = self.get_product_type_cfg_value("missionStartDate")
225+
end_date_str = self.get_product_type_cfg_value("missionEndDate")
226+
return {"start_date": start_date_str, "end_date": end_date_str}
227227

228228
result = {}
229229
result["start_date"] = start_date.strftime("%Y-%m-%dT%H:%M:%SZ")
@@ -273,7 +273,7 @@ def _create_products_from_tiles(
273273
params.update({"add_filter": add_filter_value})
274274

275275
if isinstance(params["year"], int) or isinstance(params["year"], str):
276-
list_years = [params["year"]]
276+
list_years = [str(params["year"])]
277277
else:
278278
list_years = params["year"]
279279
for year in list_years:
@@ -347,8 +347,10 @@ def _create_products_without_tiles(
347347
# product type with assets mapping
348348
assets_mapping = filters.pop("assets_mapping", None)
349349
products = []
350-
start_index = prep.items_per_page * (prep.page - 1)
351-
end_index = start_index + prep.items_per_page - 1
350+
per_page = getattr(prep, "items_per_page", DEFAULT_ITEMS_PER_PAGE)
351+
page = getattr(prep, "PAGE", 1)
352+
start_index = per_page * (page - 1)
353+
end_index = start_index + per_page - 1
352354
grouped_by = filters.pop("grouped_by", None)
353355
if grouped_by: # dataset with several files differentiated by one parameter
354356
format_params = {k: str(v) for k, v in filters.items() if v}
@@ -374,12 +376,14 @@ def _create_products_without_tiles(
374376
assets = AssetsDict(product=product)
375377
for key, mapping in assets_mapping.items():
376378
download_link = mapping["href"].format(**filters)
377-
assets[key] = Asset(
378-
product=product,
379-
key=key,
380-
href=download_link,
381-
title=mapping["title"],
382-
type=mapping["type"],
379+
assets.update(
380+
{
381+
key: {
382+
"href": download_link,
383+
"title": mapping["title"],
384+
"type": mapping["type"],
385+
}
386+
}
383387
)
384388
product.assets = assets
385389
products.append(product)
@@ -404,7 +408,7 @@ def _create_products_without_tiles(
404408

405409
def _get_tile_from_product_id(
406410
self, query_params: dict[str, Any]
407-
) -> Optional[tuple[dict[str, list[dict[str, Any]]], int]]:
411+
) -> Optional[tuple[dict[str, list[dict[str, Any]]], str]]:
408412
"""fetch the tile for a specific product id from the provider
409413
returns a a dict with a list of length 1 to simplify further processing
410414
"""
@@ -467,7 +471,7 @@ def _get_tiles_for_filters(
467471
if isinstance(filter_params["year"], int) or isinstance(
468472
filter_params["year"], str
469473
):
470-
list_years = [filter_params["year"]]
474+
list_years = [str(filter_params["year"])]
471475
else:
472476
list_years = filter_params["year"]
473477
all_tiles = {}
@@ -513,8 +517,8 @@ def query(
513517
:param kwargs: additional search arguments
514518
:returns: list of products and total number of products
515519
"""
516-
page = prep.page
517-
items_per_page = prep.items_per_page
520+
page = getattr(prep, "page", 1)
521+
items_per_page = getattr(prep, "items_per_page", DEFAULT_ITEMS_PER_PAGE)
518522

519523
# get year from start/end time if not given separately
520524
start_time = kwargs.pop("startTimeFromAscendingNode", None)

0 commit comments

Comments
 (0)