From 88f03f0408add83c3812d062829206ce53c2c0be Mon Sep 17 00:00:00 2001 From: ogabrielluiz Date: Thu, 13 Jun 2024 16:30:38 -0300 Subject: [PATCH] refactor: Update Vertex class to improve handling of template_dicts inputs Refactor the Vertex class to improve the handling of template_dicts inputs. Instead of using list comprehensions, the code now uses explicit loops to append the required and optional inputs. This change enhances the readability and maintainability of the code. --- .../base/langflow/graph/vertex/base.py | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/src/backend/base/langflow/graph/vertex/base.py b/src/backend/base/langflow/graph/vertex/base.py index 17d364a03..64f64aed9 100644 --- a/src/backend/base/langflow/graph/vertex/base.py +++ b/src/backend/base/langflow/graph/vertex/base.py @@ -234,16 +234,15 @@ class Vertex: self.has_session_id = "session_id" in template_dicts - self.required_inputs = [ - template_dicts[key]["type"] for key, value in template_dicts.items() if value["required"] - ] - self.optional_inputs = [ - template_dicts[key]["type"] for key, value in template_dicts.items() if not value["required"] - ] - # Add the template_dicts[key]["input_types"] to the optional_inputs - self.optional_inputs.extend( - [input_type for value in template_dicts.values() for input_type in value.get("input_types", [])] - ) + self.required_inputs = [] + self.optional_inputs = [] + for value_dict in template_dicts.values(): + list_to_append = self.required_inputs if value_dict.get("required") else self.optional_inputs + + if "type" in value_dict: + list_to_append.append(value_dict["type"]) + elif "input_types" in value_dict: + list_to_append.extend(value_dict["input_types"]) template_dict = self.data["node"]["template"] self.vertex_type = (