Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

style: Fix type comparison issues in codebase #3606

Merged
merged 3 commits into from
Aug 29, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/backend/base/langflow/custom/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ def add_output_types(frontend_node: CustomComponentFrontendNode, return_types: l
"traceback": traceback.format_exc(),
},
)
if return_type == str:
if return_type is str:
return_type = "Text"
elif hasattr(return_type, "__name__"):
return_type = return_type.__name__
Expand Down Expand Up @@ -85,7 +85,7 @@ def add_base_classes(frontend_node: CustomComponentFrontendNode, return_types: l
)

base_classes = get_base_classes(return_type_instance)
if return_type_instance == str:
if return_type_instance is str:
base_classes.append("Text")

for base_class in base_classes:
Expand Down
2 changes: 1 addition & 1 deletion src/backend/base/langflow/helpers/custom.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@


def format_type(type_: Any) -> str:
if type_ == str:
if type_ is str:
type_ = "Text"
elif hasattr(type_, "__name__"):
type_ = type_.__name__
Expand Down
4 changes: 2 additions & 2 deletions src/backend/base/langflow/services/settings/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ def is_list_of_any(field: FieldInfo) -> bool:
else:
union_args = []

return field.annotation.__origin__ == list or any(
arg.__origin__ == list for arg in union_args if hasattr(arg, "__origin__")
return field.annotation.__origin__ is list or any(
arg.__origin__ is list for arg in union_args if hasattr(arg, "__origin__")
)
except AttributeError:
return False
Expand Down
2 changes: 1 addition & 1 deletion src/backend/base/langflow/template/field/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ def serialize_file_path(self, value):

@field_serializer("field_type")
def serialize_field_type(self, value, _info):
if value == float and self.range_spec is None:
if value is float and self.range_spec is None:
self.range_spec = RangeSpec()
return value

Expand Down
6 changes: 3 additions & 3 deletions src/backend/tests/unit/io/test_io_schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ def test_non_standard_field_types_handling(self):
input_instance = FileInput(name="file_field")
schema = create_input_schema([input_instance])
field_info = schema.model_fields["file_field"]
assert field_info.annotation == str
assert field_info.annotation is str

# Inputs with mixed required and optional fields are processed correctly
def test_mixed_required_optional_fields_processing(self):
Expand Down Expand Up @@ -184,7 +184,7 @@ def test_is_list_handling(self):
input_instance = StrInput(name="test_field", is_list=True)
schema = create_input_schema([input_instance])
field_info = schema.model_fields["test_field"]
assert field_info.annotation == list[str]
assert field_info.annotation is list[str]

# Converting FieldTypes to corresponding Python types
def test_field_types_conversion(self):
Expand All @@ -194,7 +194,7 @@ def test_field_types_conversion(self):
input_instance = IntInput(name="int_field")
schema = create_input_schema([input_instance])
field_info = schema.model_fields["int_field"]
assert field_info.annotation == int
assert field_info.annotation is int # Use 'is' for type comparison

# Setting default values for non-required fields
def test_default_values_for_non_required_fields(self):
Expand Down
Loading