Skip to content

Commit 3d76b87

Browse files
committed
fix: typing errors
1 parent d93c26a commit 3d76b87

File tree

2 files changed

+37
-16
lines changed

2 files changed

+37
-16
lines changed

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: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -278,18 +278,23 @@ 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):
283283
plugin = next(
284284
self.get_auth_or_download_plugins(
285285
"download", product.provider, matching_url=matching_url
286286
)
287287
)
288+
if not isinstance(plugin, Download):
289+
# basically this should not happen
290+
raise MisconfiguredError(
291+
f"Invalid download plugin for provider {plugin_conf.name}"
292+
)
293+
return plugin
288294
else:
289295
raise MisconfiguredError(
290296
f"No download plugin configured for provider {plugin_conf.name}."
291297
)
292-
return plugin
293298

294299
def get_auth_plugin(
295300
self, associated_plugin: PluginTopic, product: Optional[EOProduct] = None
@@ -307,7 +312,7 @@ def get_auth_plugin(
307312
:returns: The Authentication plugin
308313
"""
309314
# matching url from product to download
310-
matching_url = ""
315+
matching_url = None
311316
if product:
312317
matching_url = _get_matching_url_for_product(product)
313318
if not matching_url:
@@ -323,6 +328,11 @@ def get_auth_plugin(
323328
matching_conf=associated_plugin.config,
324329
)
325330
)
331+
if not isinstance(auth_plugin, Authentication):
332+
# basically this should not happen
333+
raise MisconfiguredError(
334+
f"Invalid auth plugin found: {auth_plugin.config}"
335+
)
326336
except StopIteration:
327337
auth_plugin = None
328338
return auth_plugin
@@ -333,7 +343,7 @@ def get_auth_or_download_plugins(
333343
provider: str,
334344
matching_url: Optional[str] = None,
335345
matching_conf: Optional[PluginConfig] = None,
336-
) -> Iterator[Authentication]:
346+
) -> Iterator[Union[Authentication, Download]]:
337347
"""Build and return the authentication plugin for the given provider and
338348
matching conf or url
339349
@@ -379,18 +389,17 @@ def get_auth_or_download_plugins(
379389
):
380390
plugin_conf.priority = provider_conf.priority
381391
if plugin_type == "auth":
382-
plugin = cast(
392+
yield cast(
383393
Authentication,
384394
self._build_plugin(
385395
plugin_provider, plugin_conf, Authentication
386396
),
387397
)
388398
else:
389-
plugin = cast(
399+
yield cast(
390400
Download,
391401
self._build_plugin(plugin_provider, plugin_conf, Download),
392402
)
393-
yield plugin
394403
else:
395404
continue
396405

@@ -419,7 +428,11 @@ def get_auth(
419428
):
420429
# not the plugin we were looking for
421430
continue
422-
if auth_plugin and callable(getattr(auth_plugin, "authenticate", None)):
431+
if (
432+
auth_plugin
433+
and isinstance(auth_plugin, Authentication)
434+
and callable(getattr(auth_plugin, "authenticate", None))
435+
):
423436
try:
424437
auth = auth_plugin.authenticate()
425438
return auth

0 commit comments

Comments
 (0)