From 2214da07c5a910872eadd7083c0900fa5052e25d Mon Sep 17 00:00:00 2001 From: Ipuch Date: Tue, 31 Oct 2023 16:46:06 -0400 Subject: [PATCH 1/2] Solving a critical issue of code climate --- bioptim/interfaces/solver_options.py | 31 +++++++++++++--------------- 1 file changed, 14 insertions(+), 17 deletions(-) diff --git a/bioptim/interfaces/solver_options.py b/bioptim/interfaces/solver_options.py index bd0a6e547..aa8cb2a42 100644 --- a/bioptim/interfaces/solver_options.py +++ b/bioptim/interfaces/solver_options.py @@ -858,23 +858,20 @@ def set_maximum_iterations(self, num: int): def as_dict(self, solver): options = {} - for key in self.__annotations__.keys(): - if ( - key == "_acados_dir" - or key == "_cost_type" - or key == "_constr_type" - or key == "_has_tolerance_changed" - or key == "_only_first_options_has_changed" - or key == "type" - or key == "_c_compile" - or key == "_c_generated_code_path" - or key == "_acados_model_name" - ): - continue - if key[0] == "_": - options[key[1:]] = self.__getattribute__(key) - else: - options[key] = self.__getattribute__(key) + keys_to_skip = { + "_acados_dir", "_cost_type", "_constr_type", "_has_tolerance_changed", + "_only_first_options_has_changed", "type", "_c_compile", + "_c_generated_code_path", "_acados_model_name" + } + + # Select the set of relevant keys before entering the loop + relevant_keys = set(self.__annotations__.keys()) - keys_to_skip + + # Iterate only over relevant keys + for key in relevant_keys: + option_key = key[1:] if key[0] == "_" else key + options[option_key] = getattr(self, key) + return options @property From af08026ff9bd55bfca72b1ccbf05cb73ad9d6f88 Mon Sep 17 00:00:00 2001 From: Ipuch Date: Tue, 31 Oct 2023 16:46:24 -0400 Subject: [PATCH 2/2] black --- bioptim/interfaces/solver_options.py | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/bioptim/interfaces/solver_options.py b/bioptim/interfaces/solver_options.py index aa8cb2a42..6816d7e6d 100644 --- a/bioptim/interfaces/solver_options.py +++ b/bioptim/interfaces/solver_options.py @@ -859,9 +859,15 @@ def set_maximum_iterations(self, num: int): def as_dict(self, solver): options = {} keys_to_skip = { - "_acados_dir", "_cost_type", "_constr_type", "_has_tolerance_changed", - "_only_first_options_has_changed", "type", "_c_compile", - "_c_generated_code_path", "_acados_model_name" + "_acados_dir", + "_cost_type", + "_constr_type", + "_has_tolerance_changed", + "_only_first_options_has_changed", + "type", + "_c_compile", + "_c_generated_code_path", + "_acados_model_name", } # Select the set of relevant keys before entering the loop