Skip to content

Commit e266451

Browse files
committed
fix: typing errors
1 parent d93c26a commit e266451

2 files changed

Lines changed: 29 additions & 19 deletions

File tree

eodag/config.py

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -933,14 +933,22 @@ def build_mapping_from_env(
933933
# try converting env_value type from type hints
934934
if "list" in str(env_type):
935935
# convert str to array and then cast (only working for list[str] type)
936-
env_value = env_value.split(",")
937-
try:
938-
env_value = cast_scalar_value(env_value, env_type)
939-
except TypeError:
940-
logger.warning(
941-
f"Could not convert {parts[0]} value {env_value} to {env_type}"
942-
)
943-
mapping[parts[0]] = env_value
936+
env_value_list = env_value.split(",")
937+
try:
938+
env_value_list = cast_scalar_value(env_value_list, env_type)
939+
except TypeError:
940+
logger.warning(
941+
f"Could not convert {parts[0]} value {env_value} to {env_type}"
942+
)
943+
mapping[parts[0]] = env_value_list
944+
else:
945+
try:
946+
env_value = cast_scalar_value(env_value, env_type)
947+
except TypeError:
948+
logger.warning(
949+
f"Could not convert {parts[0]} value {env_value} to {env_type}"
950+
)
951+
mapping[parts[0]] = env_value
944952
else:
945953
new_map = mapping.setdefault(parts[0], {})
946954
build_mapping_from_env("__".join(parts[1:]), env_value, new_map)

eodag/plugins/manager.py

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,7 @@ def get_plugin() -> Union[Search, Api]:
266266
for config in sorted(configs, key=attrgetter("priority"), reverse=True):
267267
yield get_plugin()
268268

269-
def get_download_plugin(self, product: EOProduct) -> Union[Download, Api]:
269+
def get_download_plugin(self, product: EOProduct) -> PluginTopic:
270270
"""Build and return the download plugin capable of downloading the given
271271
product.
272272
@@ -278,9 +278,9 @@ def get_download_plugin(self, product: EOProduct) -> Union[Download, Api]:
278278
if api := getattr(plugin_conf, "api", None):
279279
plugin_conf.api.products = plugin_conf.products
280280
plugin_conf.api.priority = plugin_conf.priority
281-
plugin = cast(Api, self._build_plugin(product.provider, api, Api))
281+
return cast(Api, self._build_plugin(product.provider, api, Api))
282282
elif getattr(plugin_conf, "download", None):
283-
plugin = next(
283+
return next(
284284
self.get_auth_or_download_plugins(
285285
"download", product.provider, matching_url=matching_url
286286
)
@@ -289,11 +289,10 @@ def get_download_plugin(self, product: EOProduct) -> Union[Download, Api]:
289289
raise MisconfiguredError(
290290
f"No download plugin configured for provider {plugin_conf.name}."
291291
)
292-
return plugin
293292

294293
def get_auth_plugin(
295294
self, associated_plugin: PluginTopic, product: Optional[EOProduct] = None
296-
) -> Optional[Authentication]:
295+
) -> Optional[PluginTopic]:
297296
"""Build and return the authentication plugin associated to the given
298297
search/download plugin
299298
@@ -307,7 +306,7 @@ def get_auth_plugin(
307306
:returns: The Authentication plugin
308307
"""
309308
# matching url from product to download
310-
matching_url = ""
309+
matching_url = None
311310
if product:
312311
matching_url = _get_matching_url_for_product(product)
313312
if not matching_url:
@@ -333,7 +332,7 @@ def get_auth_or_download_plugins(
333332
provider: str,
334333
matching_url: Optional[str] = None,
335334
matching_conf: Optional[PluginConfig] = None,
336-
) -> Iterator[Authentication]:
335+
) -> Iterator[Union[Authentication, Download]]:
337336
"""Build and return the authentication plugin for the given provider and
338337
matching conf or url
339338
@@ -379,18 +378,17 @@ def get_auth_or_download_plugins(
379378
):
380379
plugin_conf.priority = provider_conf.priority
381380
if plugin_type == "auth":
382-
plugin = cast(
381+
yield cast(
383382
Authentication,
384383
self._build_plugin(
385384
plugin_provider, plugin_conf, Authentication
386385
),
387386
)
388387
else:
389-
plugin = cast(
388+
yield cast(
390389
Download,
391390
self._build_plugin(plugin_provider, plugin_conf, Download),
392391
)
393-
yield plugin
394392
else:
395393
continue
396394

@@ -419,7 +417,11 @@ def get_auth(
419417
):
420418
# not the plugin we were looking for
421419
continue
422-
if auth_plugin and callable(getattr(auth_plugin, "authenticate", None)):
420+
if (
421+
auth_plugin
422+
and isinstance(auth_plugin, Authentication)
423+
and callable(getattr(auth_plugin, "authenticate", None))
424+
):
423425
try:
424426
auth = auth_plugin.authenticate()
425427
return auth

0 commit comments

Comments
 (0)