Skip to content

Commit 48fb846

Browse files
refactor: change typing annotations in tests folder (#3594)
* refactor(log_router.py): change variable type annotation from List to list for better consistency refactor(utils.py): change variable type annotation from Dict to dict for better consistency refactor(base.py): change variable type annotation from Optional to Union for better clarity refactor(callback.py): change variable type annotation from Dict to dict for better consistency refactor(chat.py): change variable type annotation from Optional to Union for better clarity refactor(endpoints.py): change variable type annotation from Optional to Union for better clarity refactor(flows.py): change variable type annotation from List to list for better consistency refactor(api): update response_model annotations to use lowercase list for consistency and improve readability refactor(store.py): update type annotations for query parameters in get_components endpoint to improve code readability and maintainability feat(store.py): add support for type hinting Union and list types in query parameters for better data validation and documentation * run make format * refactor(input_mixin.py): update typing annotations for variables to use union types for better clarity and compatibility with Python 3.10 refactor(inputs.py): update typing annotations for variables to use union types and import necessary modules for compatibility with Python 3.10 * refactor(base.py): remove unnecessary imports and update typing for fields in Input and Output classes feat(base.py): add support for specifying field types more explicitly in Input and Output classes feat(frontend_node/base.py): enhance typing and field definitions in FrontendNode class feat(frontend_node/custom_components.py): improve typing and field definitions in CustomComponentFrontendNode and ComponentFrontendNode classes feat(template/base.py): update typing for fields in Template class and remove unnecessary imports * refactor(inputs): remove unnecessary Optional import from typing in input_mixin.py and inputs.py files to improve code readability and maintainability * refactor(schema.py): change 'Type' to 'type' for consistency in type annotations refactor(schema.py): change 'list' to 'List' and 'Literal' to 'literal' for correct type hinting in create_input_schema function * refactor(utils.py): change typing annotations from List and Union to list and type to follow PEP 585 standards refactor(test_schema.py): change typing annotations from List and List to list and list to follow PEP 585 standards refactor(test_graph.py): change typing annotations from Type and Union to type and Vertex | None to follow PEP 585 standards refactor(test_io_schema.py): change typing annotations from List and List to list and list to follow PEP 585 standards refactor(test_custom_component.py): update file reading method to remove unnecessary "r" mode refactor(test_helper_components.py): update file reading method to remove unnecessary "r" mode refactor(test_kubernetes_secrets.py): update b64encode method argument to bytes type refactor(test_template.py): change typing annotations from Optional, List, and Dict to list, dict, and None to follow PEP 585 standards * [autofix.ci] apply automated fixes --------- Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
1 parent 1883710 commit 48fb846

File tree

6 files changed

+9
-12
lines changed

6 files changed

+9
-12
lines changed

src/backend/tests/integration/utils.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import os
2-
from typing import List
32

43
from astrapy.admin import parse_api_endpoint
54
from langflow.field_typing import Embeddings
@@ -43,10 +42,10 @@ def __init__(self):
4342
def mock_embedding(text: str):
4443
return [len(text) / 2, len(text) / 5, len(text) / 10]
4544

46-
def embed_documents(self, texts: List[str]) -> List[List[float]]:
45+
def embed_documents(self, texts: list[str]) -> list[list[float]]:
4746
self.embedded_documents = texts
4847
return [self.mock_embedding(text) for text in texts]
4948

50-
def embed_query(self, text: str) -> List[float]:
49+
def embed_query(self, text: str) -> list[float]:
5150
self.embedded_query = text
5251
return self.mock_embedding(text)

src/backend/tests/unit/graph/test_graph.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import copy
22
import json
33
import pickle
4-
from typing import Type, Union
54

65
import pytest
76

@@ -62,7 +61,7 @@ def sample_nodes():
6261
]
6362

6463

65-
def get_node_by_type(graph, node_type: Type[Vertex]) -> Union[Vertex, None]:
64+
def get_node_by_type(graph, node_type: type[Vertex]) -> Vertex | None:
6665
"""Get a node by type"""
6766
return next((node for node in graph.vertices if isinstance(node, node_type)), None)
6867

src/backend/tests/unit/test_custom_component.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ def client():
1919

2020
@pytest.fixture
2121
def code_component_with_multiple_outputs():
22-
with open("src/backend/tests/data/component_multiple_outputs.py", "r") as f:
22+
with open("src/backend/tests/data/component_multiple_outputs.py") as f:
2323
code = f.read()
2424
return Component(_code=code)
2525

src/backend/tests/unit/test_helper_components.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ def client():
3939
def test_uuid_generator_component():
4040
# Arrange
4141
uuid_generator_component = helpers.IDGeneratorComponent()
42-
uuid_generator_component._code = open(helpers.IDGenerator.__file__, "r").read()
42+
uuid_generator_component._code = open(helpers.IDGenerator.__file__).read()
4343

4444
frontend_node, _ = build_custom_component_template(uuid_generator_component)
4545

src/backend/tests/unit/test_kubernetes_secrets.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,13 +33,13 @@ def test_create_secret(secret_manager, mocker):
3333
kind="Secret",
3434
metadata=V1ObjectMeta(name="test-secret"),
3535
type="Opaque",
36-
data={"key": b64encode("value".encode()).decode()},
36+
data={"key": b64encode(b"value").decode()},
3737
),
3838
)
3939

4040

4141
def test_get_secret(secret_manager, mocker):
42-
mock_secret = V1Secret(data={"key": b64encode("value".encode()).decode()})
42+
mock_secret = V1Secret(data={"key": b64encode(b"value").decode()})
4343
mocker.patch.object(secret_manager.core_api, "read_namespaced_secret", return_value=mock_secret)
4444

4545
secret_data = secret_manager.get_secret(name="test-secret")

src/backend/tests/unit/test_template.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import importlib
2-
from typing import Dict, List, Optional
32

43
import pytest
54
from langflow.utils.util import build_template_from_function, get_base_classes, get_default_factory
@@ -27,14 +26,14 @@ class Child(Parent):
2726
class ExampleClass1(BaseModel):
2827
"""Example class 1."""
2928

30-
def __init__(self, data: Optional[List[int]] = None):
29+
def __init__(self, data: list[int] | None = None):
3130
self.data = data or [1, 2, 3]
3231

3332

3433
class ExampleClass2(BaseModel):
3534
"""Example class 2."""
3635

37-
def __init__(self, data: Optional[Dict[str, int]] = None):
36+
def __init__(self, data: dict[str, int] | None = None):
3837
self.data = data or {"a": 1, "b": 2, "c": 3}
3938

4039

0 commit comments

Comments
 (0)