From aa7f0248d42378353cc6ab2aa05438a84a05d2b3 Mon Sep 17 00:00:00 2001 From: Edwin Jose Date: Fri, 18 Oct 2024 11:41:27 -0400 Subject: [PATCH] Refactor: Eliminate Global Variables for Improved Code Maintainability - Replaced global variables with local variables or class attributes. - Enhanced code readability and reduced potential side effects. --- .../langflow/components/prototypes/CreateData.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/backend/base/langflow/components/prototypes/CreateData.py b/src/backend/base/langflow/components/prototypes/CreateData.py index 140db0b18d1..db4d5ee5582 100644 --- a/src/backend/base/langflow/components/prototypes/CreateData.py +++ b/src/backend/base/langflow/components/prototypes/CreateData.py @@ -7,13 +7,12 @@ from langflow.schema import Data from langflow.schema.dotdict import dotdict -MAX_NUMBER_OF_FIELDS = 15 - class CreateDataComponent(Component): display_name: str = "Create Data" description: str = "Dynamically create a Data with a specified number of fields." name: str = "CreateData" + MAX_FIELDS = 15 # Define a constant for maximum number of fields inputs = [ IntInput( @@ -22,7 +21,7 @@ class CreateDataComponent(Component): info="Number of fields to be added to the record.", real_time_refresh=True, value=1, - range_spec=RangeSpec(min=1, max=15, step=1, step_type="int"), + range_spec=RangeSpec(min=1, max=MAX_FIELDS, step=1, step_type="int"), ), MessageTextInput( name="text_key", @@ -50,10 +49,11 @@ def update_build_config(self, build_config: dotdict, field_value: Any, field_nam except ValueError: return build_config existing_fields = {} - if field_value_int > MAX_NUMBER_OF_FIELDS: - build_config["number_of_fields"]["value"] = MAX_NUMBER_OF_FIELDS + if field_value_int > self.MAX_FIELDS: + build_config["number_of_fields"]["value"] = self.MAX_FIELDS msg = ( - f"Number of fields cannot exceed {MAX_NUMBER_OF_FIELDS}. Try using a Component to combine two Data." + f"Number of fields cannot exceed {self.MAX_FIELDS}. " + "Please adjust the number of fields to be within the allowed limit." ) raise ValueError(msg) if len(build_config) > len(default_keys):