remove bare list, dict, Sequence, None, Any (#25058)
Some checks are pending
Build and Push API & Web / build (api, DIFY_API_IMAGE_NAME, linux/amd64, build-api-amd64) (push) Waiting to run
Build and Push API & Web / build (api, DIFY_API_IMAGE_NAME, linux/arm64, build-api-arm64) (push) Waiting to run
Build and Push API & Web / build (web, DIFY_WEB_IMAGE_NAME, linux/amd64, build-web-amd64) (push) Waiting to run
Build and Push API & Web / build (web, DIFY_WEB_IMAGE_NAME, linux/arm64, build-web-arm64) (push) Waiting to run
Build and Push API & Web / create-manifest (api, DIFY_API_IMAGE_NAME, merge-api-images) (push) Blocked by required conditions
Build and Push API & Web / create-manifest (web, DIFY_WEB_IMAGE_NAME, merge-web-images) (push) Blocked by required conditions
Main CI Pipeline / Check Changed Files (push) Waiting to run
Main CI Pipeline / API Tests (push) Blocked by required conditions
Main CI Pipeline / Web Tests (push) Blocked by required conditions
Main CI Pipeline / Style Check (push) Waiting to run
Main CI Pipeline / VDB Tests (push) Blocked by required conditions
Main CI Pipeline / DB Migration Test (push) Blocked by required conditions

Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
Co-authored-by: -LAN- <laipz8200@outlook.com>
This commit is contained in:
Asuka Minato
2025-09-06 04:32:23 +09:00
committed by GitHub
parent 2b0695bdde
commit a78339a040
306 changed files with 787 additions and 817 deletions

View File

@@ -14,7 +14,7 @@ from services.account_service import AccountService, RegisterService
# Loading the .env file if it exists
def _load_env() -> None:
def _load_env():
current_file_path = pathlib.Path(__file__).absolute()
# Items later in the list have higher precedence.
files_to_load = [".env", "vdb.env"]

View File

@@ -17,7 +17,7 @@ def mock_plugin_daemon(
:return: unpatch function
"""
def unpatch() -> None:
def unpatch():
monkeypatch.undo()
monkeypatch.setattr(PluginModelClient, "invoke_llm", MockModelClass.invoke_llm)

View File

@@ -150,7 +150,7 @@ class MockTcvectordbClass:
filter: Optional[Filter] = None,
output_fields: Optional[list[str]] = None,
timeout: Optional[float] = None,
) -> list[dict]:
):
return [{"metadata": '{"doc_id":"foo1"}', "text": "text", "doc_id": "foo1", "score": 0.1}]
def collection_delete(
@@ -163,7 +163,7 @@ class MockTcvectordbClass:
):
return {"code": 0, "msg": "operation success"}
def drop_collection(self, database_name: str, collection_name: str, timeout: Optional[float] = None) -> dict:
def drop_collection(self, database_name: str, collection_name: str, timeout: Optional[float] = None):
return {"code": 0, "msg": "operation success"}

View File

@@ -26,7 +26,7 @@ def get_example_document(doc_id: str) -> Document:
@pytest.fixture
def setup_mock_redis() -> None:
def setup_mock_redis():
# get
ext_redis.redis_client.get = MagicMock(return_value=None)
@@ -48,7 +48,7 @@ class AbstractVectorTest:
self.example_doc_id = str(uuid.uuid4())
self.example_embedding = [1.001 * i for i in range(128)]
def create_vector(self) -> None:
def create_vector(self):
self.vector.create(
texts=[get_example_document(doc_id=self.example_doc_id)],
embeddings=[self.example_embedding],

View File

@@ -12,7 +12,7 @@ MOCK = os.getenv("MOCK_SWITCH", "false") == "true"
class MockedCodeExecutor:
@classmethod
def invoke(cls, language: Literal["python3", "javascript", "jinja2"], code: str, inputs: dict) -> dict:
def invoke(cls, language: Literal["python3", "javascript", "jinja2"], code: str, inputs: dict):
# invoke directly
match language:
case CodeLanguage.PYTHON3:

View File

@@ -74,7 +74,7 @@ def init_code_node(code_config: dict):
@pytest.mark.parametrize("setup_code_executor_mock", [["none"]], indirect=True)
def test_execute_code(setup_code_executor_mock):
code = """
def main(args1: int, args2: int) -> dict:
def main(args1: int, args2: int):
return {
"result": args1 + args2,
}
@@ -120,7 +120,7 @@ def test_execute_code(setup_code_executor_mock):
@pytest.mark.parametrize("setup_code_executor_mock", [["none"]], indirect=True)
def test_execute_code_output_validator(setup_code_executor_mock):
code = """
def main(args1: int, args2: int) -> dict:
def main(args1: int, args2: int):
return {
"result": args1 + args2,
}
@@ -163,7 +163,7 @@ def test_execute_code_output_validator(setup_code_executor_mock):
def test_execute_code_output_validator_depth():
code = """
def main(args1: int, args2: int) -> dict:
def main(args1: int, args2: int):
return {
"result": {
"result": args1 + args2,
@@ -281,7 +281,7 @@ def test_execute_code_output_validator_depth():
def test_execute_code_output_object_list():
code = """
def main(args1: int, args2: int) -> dict:
def main(args1: int, args2: int):
return {
"result": {
"result": args1 + args2,
@@ -356,7 +356,7 @@ def test_execute_code_output_object_list():
def test_execute_code_scientific_notation():
code = """
def main() -> dict:
def main():
return {
"result": -8.0E-5
}

View File

@@ -49,7 +49,7 @@ class DifyTestContainers:
self._containers_started = False
logger.info("DifyTestContainers initialized - ready to manage test containers")
def start_containers_with_env(self) -> None:
def start_containers_with_env(self):
"""
Start all required containers for integration testing.
@@ -230,7 +230,7 @@ class DifyTestContainers:
self._containers_started = True
logger.info("All test containers started successfully")
def stop_containers(self) -> None:
def stop_containers(self):
"""
Stop and clean up all test containers.

View File

@@ -23,7 +23,7 @@ class TestWorkflowResponseConverterFetchFilesFromVariableValue:
storage_key="storage_key_123",
)
def create_file_dict(self, file_id: str = "test_file_dict") -> dict:
def create_file_dict(self, file_id: str = "test_file_dict"):
"""Create a file dictionary with correct dify_model_identity"""
return {
"dify_model_identity": FILE_MODEL_IDENTITY,

View File

@@ -83,7 +83,7 @@ def test_client_session_initialize():
# Create message handler
def message_handler(
message: RequestResponder[types.ServerRequest, types.ClientResult] | types.ServerNotification | Exception,
) -> None:
):
if isinstance(message, Exception):
raise message

View File

@@ -777,7 +777,7 @@ def test_condition_parallel_correct_output(mock_close, mock_remove, app):
},
{
"data": {
"code": '\ndef main(arg1: str, arg2: str) -> dict:\n return {\n "result": arg1 + arg2,\n }\n', # noqa: E501
"code": '\ndef main(arg1: str, arg2: str):\n return {\n "result": arg1 + arg2,\n }\n',
"code_language": "python3",
"desc": "",
"outputs": {"result": {"children": None, "type": "string"}},

View File

@@ -233,7 +233,7 @@ FAIL_BRANCH_EDGES = [
def test_code_default_value_continue_on_error():
error_code = """
def main() -> dict:
def main():
return {
"result": 1 / 0,
}
@@ -259,7 +259,7 @@ def test_code_default_value_continue_on_error():
def test_code_fail_branch_continue_on_error():
error_code = """
def main() -> dict:
def main():
return {
"result": 1 / 0,
}

View File

@@ -276,7 +276,7 @@ def test_array_file_contains_file_name():
assert result.outputs["result"] is True
def _get_test_conditions() -> list:
def _get_test_conditions():
conditions = [
# Test boolean "is" operator
{"comparison_operator": "is", "variable_selector": ["start", "bool_true"], "value": "true"},

View File

@@ -379,7 +379,7 @@ class TestVariablePoolSerialization:
self._assert_pools_equal(reconstructed_dict, reconstructed_json)
# TODO: assert the data for file object...
def _assert_pools_equal(self, pool1: VariablePool, pool2: VariablePool) -> None:
def _assert_pools_equal(self, pool1: VariablePool, pool2: VariablePool):
"""Assert that two VariablePools contain equivalent data"""
# Compare system variables

View File

@@ -27,7 +27,7 @@ from services.feature_service import BrandingModel
class MockEmailRenderer:
"""Mock implementation of EmailRenderer protocol"""
def __init__(self) -> None:
def __init__(self):
self.rendered_templates: list[tuple[str, dict[str, Any]]] = []
def render_template(self, template_path: str, **context: Any) -> str:
@@ -39,7 +39,7 @@ class MockEmailRenderer:
class MockBrandingService:
"""Mock implementation of BrandingService protocol"""
def __init__(self, enabled: bool = False, application_title: str = "Dify") -> None:
def __init__(self, enabled: bool = False, application_title: str = "Dify"):
self.enabled = enabled
self.application_title = application_title
@@ -54,10 +54,10 @@ class MockBrandingService:
class MockEmailSender:
"""Mock implementation of EmailSender protocol"""
def __init__(self) -> None:
def __init__(self):
self.sent_emails: list[dict[str, str]] = []
def send_email(self, to: str, subject: str, html_content: str) -> None:
def send_email(self, to: str, subject: str, html_content: str):
"""Mock send_email that records sent emails"""
self.sent_emails.append(
{
@@ -134,7 +134,7 @@ class TestEmailI18nService:
email_service: EmailI18nService,
mock_renderer: MockEmailRenderer,
mock_sender: MockEmailSender,
) -> None:
):
"""Test sending email with English language"""
email_service.send_email(
email_type=EmailType.RESET_PASSWORD,
@@ -162,7 +162,7 @@ class TestEmailI18nService:
self,
email_service: EmailI18nService,
mock_sender: MockEmailSender,
) -> None:
):
"""Test sending email with Chinese language"""
email_service.send_email(
email_type=EmailType.RESET_PASSWORD,
@@ -181,7 +181,7 @@ class TestEmailI18nService:
email_config: EmailI18nConfig,
mock_renderer: MockEmailRenderer,
mock_sender: MockEmailSender,
) -> None:
):
"""Test sending email with branding enabled"""
# Create branding service with branding enabled
branding_service = MockBrandingService(enabled=True, application_title="MyApp")
@@ -215,7 +215,7 @@ class TestEmailI18nService:
self,
email_service: EmailI18nService,
mock_sender: MockEmailSender,
) -> None:
):
"""Test language fallback to English when requested language not available"""
# Request invite member in Chinese (not configured)
email_service.send_email(
@@ -233,7 +233,7 @@ class TestEmailI18nService:
self,
email_service: EmailI18nService,
mock_sender: MockEmailSender,
) -> None:
):
"""Test unknown language code falls back to English"""
email_service.send_email(
email_type=EmailType.RESET_PASSWORD,
@@ -252,7 +252,7 @@ class TestEmailI18nService:
mock_renderer: MockEmailRenderer,
mock_sender: MockEmailSender,
mock_branding_service: MockBrandingService,
) -> None:
):
"""Test sending change email for old email verification"""
# Add change email templates to config
email_config.templates[EmailType.CHANGE_EMAIL_OLD] = {
@@ -290,7 +290,7 @@ class TestEmailI18nService:
mock_renderer: MockEmailRenderer,
mock_sender: MockEmailSender,
mock_branding_service: MockBrandingService,
) -> None:
):
"""Test sending change email for new email verification"""
# Add change email templates to config
email_config.templates[EmailType.CHANGE_EMAIL_NEW] = {
@@ -325,7 +325,7 @@ class TestEmailI18nService:
def test_send_change_email_invalid_phase(
self,
email_service: EmailI18nService,
) -> None:
):
"""Test sending change email with invalid phase raises error"""
with pytest.raises(ValueError, match="Invalid phase: invalid_phase"):
email_service.send_change_email(
@@ -339,7 +339,7 @@ class TestEmailI18nService:
self,
email_service: EmailI18nService,
mock_sender: MockEmailSender,
) -> None:
):
"""Test sending raw email to single recipient"""
email_service.send_raw_email(
to="test@example.com",
@@ -357,7 +357,7 @@ class TestEmailI18nService:
self,
email_service: EmailI18nService,
mock_sender: MockEmailSender,
) -> None:
):
"""Test sending raw email to multiple recipients"""
recipients = ["user1@example.com", "user2@example.com", "user3@example.com"]
@@ -378,7 +378,7 @@ class TestEmailI18nService:
def test_get_template_missing_email_type(
self,
email_config: EmailI18nConfig,
) -> None:
):
"""Test getting template for missing email type raises error"""
with pytest.raises(ValueError, match="No templates configured for email type"):
email_config.get_template(EmailType.EMAIL_CODE_LOGIN, EmailLanguage.EN_US)
@@ -386,7 +386,7 @@ class TestEmailI18nService:
def test_get_template_missing_language_and_english(
self,
email_config: EmailI18nConfig,
) -> None:
):
"""Test error when neither requested language nor English fallback exists"""
# Add template without English fallback
email_config.templates[EmailType.EMAIL_CODE_LOGIN] = {
@@ -407,7 +407,7 @@ class TestEmailI18nService:
mock_renderer: MockEmailRenderer,
mock_sender: MockEmailSender,
mock_branding_service: MockBrandingService,
) -> None:
):
"""Test subject templating with custom variables"""
# Add template with variable in subject
email_config.templates[EmailType.OWNER_TRANSFER_NEW_NOTIFY] = {
@@ -437,7 +437,7 @@ class TestEmailI18nService:
sent_email = mock_sender.sent_emails[0]
assert sent_email["subject"] == "You are now the owner of My Workspace"
def test_email_language_from_language_code(self) -> None:
def test_email_language_from_language_code(self):
"""Test EmailLanguage.from_language_code method"""
assert EmailLanguage.from_language_code("zh-Hans") == EmailLanguage.ZH_HANS
assert EmailLanguage.from_language_code("en-US") == EmailLanguage.EN_US
@@ -448,7 +448,7 @@ class TestEmailI18nService:
class TestEmailI18nIntegration:
"""Integration tests for email i18n components"""
def test_create_default_email_config(self) -> None:
def test_create_default_email_config(self):
"""Test creating default email configuration"""
config = create_default_email_config()
@@ -476,7 +476,7 @@ class TestEmailI18nIntegration:
assert EmailLanguage.ZH_HANS in config.templates[EmailType.RESET_PASSWORD]
assert EmailLanguage.ZH_HANS in config.templates[EmailType.INVITE_MEMBER]
def test_get_email_i18n_service(self) -> None:
def test_get_email_i18n_service(self):
"""Test getting global email i18n service instance"""
service1 = get_email_i18n_service()
service2 = get_email_i18n_service()
@@ -484,7 +484,7 @@ class TestEmailI18nIntegration:
# Should return the same instance
assert service1 is service2
def test_flask_email_renderer(self) -> None:
def test_flask_email_renderer(self):
"""Test FlaskEmailRenderer implementation"""
renderer = FlaskEmailRenderer()
@@ -494,7 +494,7 @@ class TestEmailI18nIntegration:
with pytest.raises(TemplateNotFound):
renderer.render_template("test.html", foo="bar")
def test_flask_mail_sender_not_initialized(self) -> None:
def test_flask_mail_sender_not_initialized(self):
"""Test FlaskMailSender when mail is not initialized"""
sender = FlaskMailSender()
@@ -514,7 +514,7 @@ class TestEmailI18nIntegration:
# Restore original mail
libs.email_i18n.mail = original_mail
def test_flask_mail_sender_initialized(self) -> None:
def test_flask_mail_sender_initialized(self):
"""Test FlaskMailSender when mail is initialized"""
sender = FlaskMailSender()

View File

@@ -4,7 +4,7 @@ from Crypto.PublicKey import RSA
from libs import gmpy2_pkcs10aep_cipher
def test_gmpy2_pkcs10aep_cipher() -> None:
def test_gmpy2_pkcs10aep_cipher():
rsa_key_pair = pyrsa.newkeys(2048)
public_key = rsa_key_pair[0].save_pkcs1()
private_key = rsa_key_pair[1].save_pkcs1()

View File

@@ -1,7 +1,7 @@
from models.account import TenantAccountRole
def test_account_is_privileged_role() -> None:
def test_account_is_privileged_role():
assert TenantAccountRole.ADMIN == "admin"
assert TenantAccountRole.OWNER == "owner"
assert TenantAccountRole.EDITOR == "editor"