Skip to content

armgit / dify

Public Imported from GitHub
0

Build Agentic workflows, RAG pipelines, with rich AI model and tool support on one collaborative workspace. Deploy on cloud, VPC, or self-hosted, so teams move from prototype to production without rebuilding the stack.

refactor: replace deprecated Iterator with Generator in contextmanagers #35433 (#35441)

Mallikharjuna Mulpuri0b60bf6ef081
diff --git a/api/core/app/file_access/scope.py b/api/core/app/file_access/scope.py
index 80d504ef1c0..a583301f9b7 100644
--- a/api/core/app/file_access/scope.py
+++ b/api/core/app/file_access/scope.py
@@ -1,6 +1,6 @@
from __future__ import annotations
-from collections.abc import Iterator
+from collections.abc import Generator # Changed from Iterator
from contextlib import contextmanager
from contextvars import ContextVar
from dataclasses import dataclass
@@ -32,7 +32,7 @@ def get_current_file_access_scope() -> FileAccessScope | None:
@contextmanager
-def bind_file_access_scope(scope: FileAccessScope) -> Iterator[None]:
+def bind_file_access_scope(scope: FileAccessScope) -> Generator[None, None, None]: # Changed from Iterator[None]
token = _current_file_access_scope.set(scope)
try:
yield
diff --git a/api/libs/flask_utils.py b/api/libs/flask_utils.py
index 52fc787c790..838af2bf321 100644
--- a/api/libs/flask_utils.py
+++ b/api/libs/flask_utils.py
@@ -1,5 +1,5 @@
import contextvars
-from collections.abc import Iterator
+from collections.abc import Generator # Changed from Iterator
from contextlib import contextmanager
from typing import TYPE_CHECKING
@@ -13,7 +13,7 @@ if TYPE_CHECKING:
def preserve_flask_contexts(
flask_app: Flask,
context_vars: contextvars.Context,
-) -> Iterator[None]:
+) -> Generator[None, None, None]: # Changed from Iterator[None]
"""
A context manager that handles:
1. flask-login's UserProxy copy
diff --git a/api/providers/vdb/vdb-analyticdb/src/dify_vdb_analyticdb/analyticdb_vector_sql.py b/api/providers/vdb/vdb-analyticdb/src/dify_vdb_analyticdb/analyticdb_vector_sql.py
index b2908ebdae7..11398efb586 100644
--- a/api/providers/vdb/vdb-analyticdb/src/dify_vdb_analyticdb/analyticdb_vector_sql.py
+++ b/api/providers/vdb/vdb-analyticdb/src/dify_vdb_analyticdb/analyticdb_vector_sql.py
@@ -1,6 +1,6 @@
import json
import uuid
-from collections.abc import Iterator
+from collections.abc import Generator # Added Generator
from contextlib import contextmanager
from typing import Any
@@ -75,7 +75,7 @@ class AnalyticdbVectorBySql:
)
@contextmanager
- def _get_cursor(self) -> Iterator[Any]:
+ def _get_cursor(self) -> Generator[Any, None, None]: # Changed from Iterator[Any]
assert self.pool is not None, "Connection pool is not initialized"
conn = self.pool.getconn()
cur = conn.cursor()
diff --git a/api/services/file_service.py b/api/services/file_service.py
index 52da2a7951f..f60afe2f19d 100644
--- a/api/services/file_service.py
+++ b/api/services/file_service.py
@@ -2,7 +2,7 @@ import base64
import hashlib
import os
import uuid
-from collections.abc import Iterator, Sequence
+from collections.abc import Generator, Sequence # Changed Iterator to Generator
from contextlib import contextmanager, suppress
from tempfile import NamedTemporaryFile
from typing import Literal
@@ -324,7 +324,7 @@ class FileService:
def build_upload_files_zip_tempfile(
*,
upload_files: Sequence[UploadFile],
- ) -> Iterator[str]:
+ ) -> Generator[str, None, None]: # Changed from Iterator[str]
"""
Build a ZIP from `UploadFile`s and yield a tempfile path.