diff --git a/.github/workflows/style.yml b/.github/workflows/style.yml index aaabec0cb..73383ced1 100644 --- a/.github/workflows/style.yml +++ b/.github/workflows/style.yml @@ -48,6 +48,10 @@ jobs: if: steps.changed-files.outputs.any_changed == 'true' run: dev/basedpyright-check + - name: Run Mypy Type Checks + if: steps.changed-files.outputs.any_changed == 'true' + run: uv --directory api run mypy --exclude-gitignore --exclude 'tests/' --exclude 'migrations/' --check-untyped-defs --disable-error-code=import-untyped . + - name: Dotenv check if: steps.changed-files.outputs.any_changed == 'true' run: uv run --project api dotenv-linter ./api/.env.example ./web/.env.example diff --git a/api/app_factory.py b/api/app_factory.py index 8a0417dd7..17c376de7 100644 --- a/api/app_factory.py +++ b/api/app_factory.py @@ -25,6 +25,9 @@ def create_flask_app_with_configs() -> DifyApp: # add an unique identifier to each request RecyclableContextVar.increment_thread_recycles() + # Capture the decorator's return value to avoid pyright reportUnusedFunction + _ = before_request + return dify_app diff --git a/api/core/plugin/utils/chunk_merger.py b/api/core/plugin/utils/chunk_merger.py index 3fb4d5d9e..21ca2d8d3 100644 --- a/api/core/plugin/utils/chunk_merger.py +++ b/api/core/plugin/utils/chunk_merger.py @@ -1,6 +1,6 @@ from collections.abc import Generator from dataclasses import dataclass, field -from typing import TypeVar, Union +from typing import TypeVar, Union, cast from core.agent.entities import AgentInvokeMessage from core.tools.entities.tool_entities import ToolInvokeMessage @@ -85,7 +85,7 @@ def merge_blob_chunks( message=ToolInvokeMessage.BlobMessage(blob=files[chunk_id].data[: files[chunk_id].bytes_written]), meta=resp.meta, ) - yield merged_message + yield cast(MessageType, merged_message) # Clean up the buffer del files[chunk_id] else: diff --git a/api/core/tools/tool_manager.py b/api/core/tools/tool_manager.py index 6dacaa050..9897045d9 100644 --- a/api/core/tools/tool_manager.py +++ b/api/core/tools/tool_manager.py @@ -642,7 +642,7 @@ class ToolManager: include_set=dify_config.POSITION_TOOL_INCLUDES_SET, exclude_set=dify_config.POSITION_TOOL_EXCLUDES_SET, data=provider, - name_func=lambda x: x.identity.name, + name_func=lambda x: x.entity.identity.name, ): continue user_provider = ToolTransformService.builtin_provider_to_user_provider( diff --git a/api/pyproject.toml b/api/pyproject.toml index 7416380fd..8f5a6a44a 100644 --- a/api/pyproject.toml +++ b/api/pyproject.toml @@ -166,6 +166,7 @@ dev = [ "types-python-http-client>=3.3.7.20240910", "types-redis>=4.6.0.20241004", "celery-types>=0.23.0", + "mypy~=1.17.1", ] ############################################################ diff --git a/api/pyrightconfig.json b/api/pyrightconfig.json index 80fd10558..dfffdb8cf 100644 --- a/api/pyrightconfig.json +++ b/api/pyrightconfig.json @@ -1,47 +1,28 @@ { "include": ["."], - "exclude": ["tests/", "migrations/", ".venv/"], + "exclude": [ + "tests/", + "migrations/", + ".venv/", + "models/", + "core/", + "controllers/", + "tasks/", + "services/", + "schedule/", + "extensions/", + "utils/", + "repositories/", + "libs/", + "fields/", + "factories/", + "events/", + "contexts/", + "constants/", + "configs/", + "commands.py" + ], "typeCheckingMode": "strict", "pythonVersion": "3.11", - "pythonPlatform": "All", - "reportMissingTypeStubs": false, - "reportOptionalMemberAccess": "none", - "reportOptionalIterable": "none", - "reportOptionalOperand": "none", - "reportOptionalSubscript": "none", - "reportTypedDictNotRequiredAccess": "none", - "reportPrivateImportUsage": "none", - "reportUnsupportedDunderAll": "none", - "reportUnnecessaryTypeIgnoreComment": "none", - "reportMatchNotExhaustive": "none", - "reportImplicitOverride": "none", - "reportCallInDefaultInitializer": "none", - "reportUnnecessaryIsInstance": "none", - "reportUnnecessaryComparison": "none", - "reportUnknownParameterType": "none", - "reportMissingParameterType": "none", - "reportUnknownArgumentType": "none", - "reportUnknownVariableType": "none", - "reportUnknownMemberType": "none", - "reportMissingTypeArgument": "none", - "reportUntypedFunctionDecorator": "none", - "reportUnknownLambdaType": "none", - "reportPrivateUsage": "none", - "reportConstantRedefinition": "none", - "reportIncompatibleMethodOverride": "none", - "reportIncompatibleVariableOverride": "none", - "reportOverlappingOverload": "none", - "reportPossiblyUnboundVariable": "none", - "reportUnusedImport": "none", - "reportUnusedFunction": "none", - "reportArgumentType": "none", - "reportAssignmentType": "none", - "reportAttributeAccessIssue": "none", - "reportCallIssue": "none", - "reportIndexIssue": "none", - "reportRedeclaration": "none", - "reportReturnType": "none", - "reportOperatorIssue": "none", - "reportTypeCommentUsage": "none", - "reportDeprecated": "none" + "pythonPlatform": "All" } diff --git a/api/services/dataset_service.py b/api/services/dataset_service.py index a5550c701..4b202001d 100644 --- a/api/services/dataset_service.py +++ b/api/services/dataset_service.py @@ -1198,7 +1198,7 @@ class DocumentService: "Invalid process rule mode: %s, can not find dataset process rule", process_rule.mode, ) - return + return [], "" db.session.add(dataset_process_rule) db.session.commit() lock_name = f"add_document_lock_dataset_id_{dataset.id}" diff --git a/api/services/tools/builtin_tools_manage_service.py b/api/services/tools/builtin_tools_manage_service.py index 71bc50017..bce389b94 100644 --- a/api/services/tools/builtin_tools_manage_service.py +++ b/api/services/tools/builtin_tools_manage_service.py @@ -573,7 +573,7 @@ class BuiltinToolManageService: include_set=dify_config.POSITION_TOOL_INCLUDES_SET, # type: ignore exclude_set=dify_config.POSITION_TOOL_EXCLUDES_SET, # type: ignore data=provider_controller, - name_func=lambda x: x.identity.name, + name_func=lambda x: x.entity.identity.name, ): continue diff --git a/api/uv.lock b/api/uv.lock index 987dc7243..1d872087c 100644 --- a/api/uv.lock +++ b/api/uv.lock @@ -1357,6 +1357,7 @@ dev = [ { name = "faker" }, { name = "hypothesis" }, { name = "lxml-stubs" }, + { name = "mypy" }, { name = "pandas-stubs" }, { name = "pytest" }, { name = "pytest-benchmark" }, @@ -1547,6 +1548,7 @@ dev = [ { name = "faker", specifier = "~=32.1.0" }, { name = "hypothesis", specifier = ">=6.131.15" }, { name = "lxml-stubs", specifier = "~=0.5.1" }, + { name = "mypy", specifier = "~=1.17.1" }, { name = "pandas-stubs", specifier = "~=2.2.3" }, { name = "pytest", specifier = "~=8.3.2" }, { name = "pytest-benchmark", specifier = "~=4.0.0" }, @@ -3287,6 +3289,32 @@ wheels = [ { url = "https://files.pythonhosted.org/packages/d8/30/9aec301e9772b098c1f5c0ca0279237c9766d94b97802e9888010c64b0ed/multidict-6.6.3-py3-none-any.whl", hash = "sha256:8db10f29c7541fc5da4defd8cd697e1ca429db743fa716325f236079b96f775a", size = 12313, upload-time = "2025-06-30T15:53:45.437Z" }, ] +[[package]] +name = "mypy" +version = "1.17.1" +source = { registry = "https://pypi.org/simple" } +dependencies = [ + { name = "mypy-extensions" }, + { name = "pathspec" }, + { name = "typing-extensions" }, +] +sdist = { url = "https://files.pythonhosted.org/packages/8e/22/ea637422dedf0bf36f3ef238eab4e455e2a0dcc3082b5cc067615347ab8e/mypy-1.17.1.tar.gz", hash = "sha256:25e01ec741ab5bb3eec8ba9cdb0f769230368a22c959c4937360efb89b7e9f01", size = 3352570, upload-time = "2025-07-31T07:54:19.204Z" } +wheels = [ + { url = "https://files.pythonhosted.org/packages/46/cf/eadc80c4e0a70db1c08921dcc220357ba8ab2faecb4392e3cebeb10edbfa/mypy-1.17.1-cp311-cp311-macosx_10_9_x86_64.whl", hash = "sha256:ad37544be07c5d7fba814eb370e006df58fed8ad1ef33ed1649cb1889ba6ff58", size = 10921009, upload-time = "2025-07-31T07:53:23.037Z" }, + { url = "https://files.pythonhosted.org/packages/5d/c1/c869d8c067829ad30d9bdae051046561552516cfb3a14f7f0347b7d973ee/mypy-1.17.1-cp311-cp311-macosx_11_0_arm64.whl", hash = "sha256:064e2ff508e5464b4bd807a7c1625bc5047c5022b85c70f030680e18f37273a5", size = 10047482, upload-time = "2025-07-31T07:53:26.151Z" }, + { url = "https://files.pythonhosted.org/packages/98/b9/803672bab3fe03cee2e14786ca056efda4bb511ea02dadcedde6176d06d0/mypy-1.17.1-cp311-cp311-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl", hash = "sha256:70401bbabd2fa1aa7c43bb358f54037baf0586f41e83b0ae67dd0534fc64edfd", size = 11832883, upload-time = "2025-07-31T07:53:47.948Z" }, + { url = "https://files.pythonhosted.org/packages/88/fb/fcdac695beca66800918c18697b48833a9a6701de288452b6715a98cfee1/mypy-1.17.1-cp311-cp311-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl", hash = "sha256:e92bdc656b7757c438660f775f872a669b8ff374edc4d18277d86b63edba6b8b", size = 12566215, upload-time = "2025-07-31T07:54:04.031Z" }, + { url = "https://files.pythonhosted.org/packages/7f/37/a932da3d3dace99ee8eb2043b6ab03b6768c36eb29a02f98f46c18c0da0e/mypy-1.17.1-cp311-cp311-musllinux_1_2_x86_64.whl", hash = "sha256:c1fdf4abb29ed1cb091cf432979e162c208a5ac676ce35010373ff29247bcad5", size = 12751956, upload-time = "2025-07-31T07:53:36.263Z" }, + { url = "https://files.pythonhosted.org/packages/8c/cf/6438a429e0f2f5cab8bc83e53dbebfa666476f40ee322e13cac5e64b79e7/mypy-1.17.1-cp311-cp311-win_amd64.whl", hash = "sha256:ff2933428516ab63f961644bc49bc4cbe42bbffb2cd3b71cc7277c07d16b1a8b", size = 9507307, upload-time = "2025-07-31T07:53:59.734Z" }, + { url = "https://files.pythonhosted.org/packages/17/a2/7034d0d61af8098ec47902108553122baa0f438df8a713be860f7407c9e6/mypy-1.17.1-cp312-cp312-macosx_10_13_x86_64.whl", hash = "sha256:69e83ea6553a3ba79c08c6e15dbd9bfa912ec1e493bf75489ef93beb65209aeb", size = 11086295, upload-time = "2025-07-31T07:53:28.124Z" }, + { url = "https://files.pythonhosted.org/packages/14/1f/19e7e44b594d4b12f6ba8064dbe136505cec813549ca3e5191e40b1d3cc2/mypy-1.17.1-cp312-cp312-macosx_11_0_arm64.whl", hash = "sha256:1b16708a66d38abb1e6b5702f5c2c87e133289da36f6a1d15f6a5221085c6403", size = 10112355, upload-time = "2025-07-31T07:53:21.121Z" }, + { url = "https://files.pythonhosted.org/packages/5b/69/baa33927e29e6b4c55d798a9d44db5d394072eef2bdc18c3e2048c9ed1e9/mypy-1.17.1-cp312-cp312-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl", hash = "sha256:89e972c0035e9e05823907ad5398c5a73b9f47a002b22359b177d40bdaee7056", size = 11875285, upload-time = "2025-07-31T07:53:55.293Z" }, + { url = "https://files.pythonhosted.org/packages/90/13/f3a89c76b0a41e19490b01e7069713a30949d9a6c147289ee1521bcea245/mypy-1.17.1-cp312-cp312-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl", hash = "sha256:03b6d0ed2b188e35ee6d5c36b5580cffd6da23319991c49ab5556c023ccf1341", size = 12737895, upload-time = "2025-07-31T07:53:43.623Z" }, + { url = "https://files.pythonhosted.org/packages/23/a1/c4ee79ac484241301564072e6476c5a5be2590bc2e7bfd28220033d2ef8f/mypy-1.17.1-cp312-cp312-musllinux_1_2_x86_64.whl", hash = "sha256:c837b896b37cd103570d776bda106eabb8737aa6dd4f248451aecf53030cdbeb", size = 12931025, upload-time = "2025-07-31T07:54:17.125Z" }, + { url = "https://files.pythonhosted.org/packages/89/b8/7409477be7919a0608900e6320b155c72caab4fef46427c5cc75f85edadd/mypy-1.17.1-cp312-cp312-win_amd64.whl", hash = "sha256:665afab0963a4b39dff7c1fa563cc8b11ecff7910206db4b2e64dd1ba25aed19", size = 9584664, upload-time = "2025-07-31T07:54:12.842Z" }, + { url = "https://files.pythonhosted.org/packages/1d/f3/8fcd2af0f5b806f6cf463efaffd3c9548a28f84220493ecd38d127b6b66d/mypy-1.17.1-py3-none-any.whl", hash = "sha256:a9f52c0351c21fe24c21d8c0eb1f62967b262d6729393397b6f443c3b773c3b9", size = 2283411, upload-time = "2025-07-31T07:53:24.664Z" }, +] + [[package]] name = "mypy-boto3-bedrock-runtime" version = "1.39.0" @@ -4038,6 +4066,15 @@ dependencies = [ ] sdist = { url = "https://files.pythonhosted.org/packages/10/9a/e3186e760c57ee5f1c27ea5cea577a0ff9abfca51eefcb4d9a4cd39aff2e/pandoc-2.4.tar.gz", hash = "sha256:ecd1f8cbb7f4180c6b5db4a17a7c1a74df519995f5f186ef81ce72a9cbd0dd9a", size = 34635, upload-time = "2024-08-07T14:33:58.016Z" } +[[package]] +name = "pathspec" +version = "0.12.1" +source = { registry = "https://pypi.org/simple" } +sdist = { url = "https://files.pythonhosted.org/packages/ca/bc/f35b8446f4531a7cb215605d100cd88b7ac6f44ab3fc94870c120ab3adbf/pathspec-0.12.1.tar.gz", hash = "sha256:a482d51503a1ab33b1c67a6c3813a26953dbdc71c31dacaef9a838c4e29f5712", size = 51043, upload-time = "2023-12-10T22:30:45Z" } +wheels = [ + { url = "https://files.pythonhosted.org/packages/cc/20/ff623b09d963f88bfde16306a54e12ee5ea43e9b597108672ff3a408aad6/pathspec-0.12.1-py3-none-any.whl", hash = "sha256:a0d503e138a4c123b27490a4f7beda6a01c6f288df0e4a8b79c7eb0dc7b4cc08", size = 31191, upload-time = "2023-12-10T22:30:43.14Z" }, +] + [[package]] name = "pgvecto-rs" version = "0.2.2"