chore(api): align Python support with 3.12 (#34419)

Co-authored-by: Asuka Minato <i@asukaminato.eu.org>
This commit is contained in:
99
2026-04-02 13:07:32 +08:00
committed by GitHub
parent cb9ee5903a
commit 8f9dbf269e
97 changed files with 410 additions and 1441 deletions

View File

@@ -1,12 +1,10 @@
import contextvars
from collections.abc import Iterator
from contextlib import contextmanager
from typing import TYPE_CHECKING, TypeVar
from typing import TYPE_CHECKING
from flask import Flask, g
T = TypeVar("T")
if TYPE_CHECKING:
from models import Account, EndUser

View File

@@ -42,13 +42,7 @@ def current_account_with_tenant():
return user, user.current_tenant_id
from typing import ParamSpec, TypeVar
P = ParamSpec("P")
R = TypeVar("R")
def login_required(func: Callable[P, R]) -> Callable[P, R | ResponseReturnValue]:
def login_required[**P, R](func: Callable[P, R]) -> Callable[P, R | ResponseReturnValue]:
"""
If you decorate a view with this, it will ensure that the current user is
logged in and authenticated before calling the actual view. (If they are

View File

@@ -1,26 +1,20 @@
import logging
import sys
import urllib.parse
from dataclasses import dataclass
from typing import NotRequired
from typing import NotRequired, TypedDict
import httpx
from pydantic import TypeAdapter, ValidationError
from core.helper.http_client_pooling import get_pooled_http_client
if sys.version_info >= (3, 12):
from typing import TypedDict
else:
from typing_extensions import TypedDict
logger = logging.getLogger(__name__)
JsonObject = dict[str, object]
JsonObjectList = list[JsonObject]
type JsonObject = dict[str, object]
type JsonObjectList = list[JsonObject]
JSON_OBJECT_ADAPTER = TypeAdapter(JsonObject)
JSON_OBJECT_LIST_ADAPTER = TypeAdapter(JsonObjectList)
JSON_OBJECT_ADAPTER: TypeAdapter[JsonObject] = TypeAdapter(JsonObject)
JSON_OBJECT_LIST_ADAPTER: TypeAdapter[JsonObjectList] = TypeAdapter(JsonObjectList)
# Reuse a pooled httpx.Client for OAuth flows (public endpoints, no SSRF proxy).
_http_client: httpx.Client = get_pooled_http_client(

View File

@@ -1,6 +1,5 @@
import sys
import urllib.parse
from typing import Any, Literal
from typing import Any, Literal, TypedDict
import httpx
from flask_login import current_user
@@ -12,11 +11,6 @@ from extensions.ext_database import db
from libs.datetime_utils import naive_utc_now
from models.source import DataSourceOauthBinding
if sys.version_info >= (3, 12):
from typing import TypedDict
else:
from typing_extensions import TypedDict
class NotionPageSummary(TypedDict):
page_id: str