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:
fawney19
2026-01-30 12:43:08 +08:00
parent a90f065ab0
commit 13487fe4e5
19 changed files with 46 additions and 1057 deletions

View File

@@ -1,3 +1,5 @@
from __future__ import annotations
from abc import ABC, abstractmethod
from typing import TYPE_CHECKING
from urllib.parse import urlencode, urlparse, urlunparse

View File

@@ -1,3 +1,5 @@
from __future__ import annotations
from typing import TYPE_CHECKING, Any
from src.core.logger import logger

View File

@@ -2,6 +2,7 @@
认证服务
"""
from __future__ import annotations
import hashlib
import secrets

View File

@@ -28,6 +28,8 @@
- 失效缓存亲和性,避免重复选择故障资源
"""
from __future__ import annotations
import hashlib
import random

View File

@@ -6,6 +6,8 @@
- URL 脱敏(用于日志记录)
"""
from __future__ import annotations
import re
from typing import TYPE_CHECKING, Any
from urllib.parse import urlencode

View File

@@ -10,6 +10,8 @@
3. 置信度计算综合考虑连续成功次数、429冷却时间、调整历史稳定性
"""
from __future__ import annotations
import statistics
from dataclasses import dataclass, field
from datetime import datetime, timezone