mirror of
https://github.com/fawney19/Aether.git
synced 2026-09-02 09:20:22 +08:00
fix: 添加 from __future__ import annotations 修复运行时类型错误
原 PR 将 Optional[X] 改为 X | None 后,如果 X 在 TYPE_CHECKING 块中导入, 会导致运行时 NameError。添加 future annotations 使类型注解延迟求值。 影响文件: - src/services/auth/service.py - src/core/api_format/utils.py - src/core/api_format/detection.py - 及其他 15 个使用 TYPE_CHECKING 的文件
This commit is contained in:
@@ -1,3 +1,5 @@
|
|||||||
|
from __future__ import annotations
|
||||||
|
|
||||||
import time
|
import time
|
||||||
from enum import Enum
|
from enum import Enum
|
||||||
from typing import TYPE_CHECKING, Any
|
from typing import TYPE_CHECKING, Any
|
||||||
|
|||||||
@@ -25,6 +25,8 @@
|
|||||||
) -> JSONResponse: ...
|
) -> JSONResponse: ...
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
from __future__ import annotations
|
||||||
|
|
||||||
|
|
||||||
import asyncio
|
import asyncio
|
||||||
import time
|
import time
|
||||||
|
|||||||
@@ -10,6 +10,8 @@ CLI Message Handler 通用基类
|
|||||||
3. 简化新格式接入 - 只需实现 ResponseParser 和少量钩子方法
|
3. 简化新格式接入 - 只需实现 ResponseParser 和少量钩子方法
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
from __future__ import annotations
|
||||||
|
|
||||||
import asyncio
|
import asyncio
|
||||||
import codecs
|
import codecs
|
||||||
import json
|
import json
|
||||||
|
|||||||
@@ -8,6 +8,8 @@
|
|||||||
- 请求/响应数据
|
- 请求/响应数据
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
from __future__ import annotations
|
||||||
|
|
||||||
import time
|
import time
|
||||||
from dataclasses import dataclass, field
|
from dataclasses import dataclass, field
|
||||||
from typing import TYPE_CHECKING, Any
|
from typing import TYPE_CHECKING, Any
|
||||||
|
|||||||
@@ -2,6 +2,8 @@
|
|||||||
Handler 基础工具函数
|
Handler 基础工具函数
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
from __future__ import annotations
|
||||||
|
|
||||||
|
|
||||||
import json
|
import json
|
||||||
from typing import TYPE_CHECKING, Any
|
from typing import TYPE_CHECKING, Any
|
||||||
|
|||||||
@@ -10,6 +10,8 @@
|
|||||||
- data_format_id 不同 -> 需要转换,检查全局开关 + 端点配置 + 转换器能力
|
- data_format_id 不同 -> 需要转换,检查全局开关 + 端点配置 + 转换器能力
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
from __future__ import annotations
|
||||||
|
|
||||||
|
|
||||||
import logging
|
import logging
|
||||||
from typing import TYPE_CHECKING
|
from typing import TYPE_CHECKING
|
||||||
|
|||||||
@@ -4,6 +4,8 @@ API 格式检测
|
|||||||
提供从请求头、响应内容等检测 API 格式的函数。
|
提供从请求头、响应内容等检测 API 格式的函数。
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
from __future__ import annotations
|
||||||
|
|
||||||
|
|
||||||
from typing import TYPE_CHECKING
|
from typing import TYPE_CHECKING
|
||||||
|
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ API 格式工具函数
|
|||||||
提供格式判断、规范化等工具函数,供整个项目使用。
|
提供格式判断、规范化等工具函数,供整个项目使用。
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
from __future__ import annotations
|
||||||
|
|
||||||
from typing import TYPE_CHECKING
|
from typing import TYPE_CHECKING
|
||||||
|
|
||||||
|
|||||||
@@ -4,6 +4,8 @@
|
|||||||
包含模块元数据、定义和状态的数据结构
|
包含模块元数据、定义和状态的数据结构
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
from __future__ import annotations
|
||||||
|
|
||||||
from dataclasses import dataclass, field
|
from dataclasses import dataclass, field
|
||||||
from enum import Enum
|
from enum import Enum
|
||||||
from typing import TYPE_CHECKING, Any
|
from typing import TYPE_CHECKING, Any
|
||||||
|
|||||||
@@ -6,6 +6,8 @@
|
|||||||
以避免 Starlette 已知的流式响应兼容性问题。
|
以避免 Starlette 已知的流式响应兼容性问题。
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
from __future__ import annotations
|
||||||
|
|
||||||
import hashlib
|
import hashlib
|
||||||
import time
|
import time
|
||||||
from typing import TYPE_CHECKING
|
from typing import TYPE_CHECKING
|
||||||
|
|||||||
@@ -4,6 +4,8 @@ LDAP 认证模块
|
|||||||
提供 LDAP/Active Directory 用户认证支持
|
提供 LDAP/Active Directory 用户认证支持
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
from __future__ import annotations
|
||||||
|
|
||||||
from typing import TYPE_CHECKING
|
from typing import TYPE_CHECKING
|
||||||
|
|
||||||
from src.core.modules.base import (
|
from src.core.modules.base import (
|
||||||
|
|||||||
@@ -4,6 +4,8 @@ OAuth 认证模块
|
|||||||
提供可配置的 OAuth 登录/绑定能力。
|
提供可配置的 OAuth 登录/绑定能力。
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
from __future__ import annotations
|
||||||
|
|
||||||
from typing import TYPE_CHECKING
|
from typing import TYPE_CHECKING
|
||||||
|
|
||||||
from src.core.modules.base import (
|
from src.core.modules.base import (
|
||||||
|
|||||||
@@ -1,3 +1,5 @@
|
|||||||
|
from __future__ import annotations
|
||||||
|
|
||||||
from abc import ABC, abstractmethod
|
from abc import ABC, abstractmethod
|
||||||
from typing import TYPE_CHECKING
|
from typing import TYPE_CHECKING
|
||||||
from urllib.parse import urlencode, urlparse, urlunparse
|
from urllib.parse import urlencode, urlparse, urlunparse
|
||||||
|
|||||||
@@ -1,3 +1,5 @@
|
|||||||
|
from __future__ import annotations
|
||||||
|
|
||||||
from typing import TYPE_CHECKING, Any
|
from typing import TYPE_CHECKING, Any
|
||||||
|
|
||||||
from src.core.logger import logger
|
from src.core.logger import logger
|
||||||
|
|||||||
@@ -2,6 +2,7 @@
|
|||||||
认证服务
|
认证服务
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
from __future__ import annotations
|
||||||
|
|
||||||
import hashlib
|
import hashlib
|
||||||
import secrets
|
import secrets
|
||||||
|
|||||||
2
src/services/cache/aware_scheduler.py
vendored
2
src/services/cache/aware_scheduler.py
vendored
@@ -28,6 +28,8 @@
|
|||||||
- 失效缓存亲和性,避免重复选择故障资源
|
- 失效缓存亲和性,避免重复选择故障资源
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
from __future__ import annotations
|
||||||
|
|
||||||
|
|
||||||
import hashlib
|
import hashlib
|
||||||
import random
|
import random
|
||||||
|
|||||||
@@ -6,6 +6,8 @@
|
|||||||
- URL 脱敏(用于日志记录)
|
- URL 脱敏(用于日志记录)
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
from __future__ import annotations
|
||||||
|
|
||||||
import re
|
import re
|
||||||
from typing import TYPE_CHECKING, Any
|
from typing import TYPE_CHECKING, Any
|
||||||
from urllib.parse import urlencode
|
from urllib.parse import urlencode
|
||||||
|
|||||||
@@ -10,6 +10,8 @@
|
|||||||
3. 置信度计算:综合考虑连续成功次数、429冷却时间、调整历史稳定性
|
3. 置信度计算:综合考虑连续成功次数、429冷却时间、调整历史稳定性
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
from __future__ import annotations
|
||||||
|
|
||||||
import statistics
|
import statistics
|
||||||
from dataclasses import dataclass, field
|
from dataclasses import dataclass, field
|
||||||
from datetime import datetime, timezone
|
from datetime import datetime, timezone
|
||||||
|
|||||||
Reference in New Issue
Block a user