refactor: use if clauses in list comprehensions to make code more pythonic (#215)

Signed-off-by: Federico Bond <federicobond@gmail.com>
Co-authored-by: Michael Beemer <beeme1mr@users.noreply.github.com>
This commit is contained in:
Federico Bond 2023-10-19 17:38:11 -03:00 committed by GitHub
parent c661ab20a4
commit 64f57fdcd4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 10 additions and 20 deletions

View File

@ -76,17 +76,11 @@ def _execute_hooks(
:param kwargs: arguments that need to be provided to the hook method
:return: a list of results from the applied hook methods
"""
if hooks:
filtered_hooks = list(
filter(
lambda hook: hook.supports_flag_value_type(flag_type=flag_type), hooks
)
)
return [
_execute_hook_checked(hook, hook_method, **kwargs)
for hook in filtered_hooks
]
return []
return [
_execute_hook_checked(hook, hook_method, **kwargs)
for hook in hooks
if hook.supports_flag_value_type(flag_type)
]
def _execute_hooks_unchecked(
@ -103,15 +97,11 @@ def _execute_hooks_unchecked(
:param kwargs: arguments that need to be provided to the hook method
:return: a list of results from the applied hook methods
"""
if hooks:
filtered_hooks = list(
filter(
lambda hook: hook.supports_flag_value_type(flag_type=flag_type), hooks
)
)
return [getattr(hook, hook_method.value)(**kwargs) for hook in filtered_hooks]
return []
return [
getattr(hook, hook_method.value)(**kwargs)
for hook in hooks
if hook.supports_flag_value_type(flag_type)
]
def _execute_hook_checked(hook: Hook, hook_method: HookType, **kwargs):