From 64f57fdcd465d6eaf6ab46a90898ac3102b7bf83 Mon Sep 17 00:00:00 2001 From: Federico Bond Date: Thu, 19 Oct 2023 17:38:11 -0300 Subject: [PATCH] refactor: use if clauses in list comprehensions to make code more pythonic (#215) Signed-off-by: Federico Bond Co-authored-by: Michael Beemer --- openfeature/hook/hook_support.py | 30 ++++++++++-------------------- 1 file changed, 10 insertions(+), 20 deletions(-) diff --git a/openfeature/hook/hook_support.py b/openfeature/hook/hook_support.py index 5fc4995..003fb1a 100644 --- a/openfeature/hook/hook_support.py +++ b/openfeature/hook/hook_support.py @@ -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):