fix: auto-fix code issues (cron)

- 修复重复导入/字段
- 修复异常处理
- 修复PEP8格式问题 (E302, E305, E501)
- 修复行长度超过100字符的问题
- 修复F821未定义名称错误
This commit is contained in:
AutoFix Bot
2026-03-01 18:19:06 +08:00
parent 8f59c7b17c
commit e46c938b40
36 changed files with 1102 additions and 28 deletions

View File

@@ -12,6 +12,7 @@ from collections.abc import Callable
from dataclasses import dataclass
from functools import wraps
@dataclass
class RateLimitConfig:
"""限流配置"""
@@ -20,6 +21,7 @@ class RateLimitConfig:
burst_size: int = 10 # 突发请求数
window_size: int = 60 # 窗口大小(秒)
@dataclass
class RateLimitInfo:
"""限流信息"""
@@ -29,6 +31,7 @@ class RateLimitInfo:
reset_time: int # 重置时间戳
retry_after: int # 需要等待的秒数
class SlidingWindowCounter:
"""滑动窗口计数器"""
@@ -60,6 +63,7 @@ class SlidingWindowCounter:
for k in old_keys:
self.requests.pop(k, None)
class RateLimiter:
"""API 限流器"""
@@ -155,9 +159,11 @@ class RateLimiter:
self.counters.clear()
self.configs.clear()
# 全局限流器实例
_rate_limiter: RateLimiter | None = None
def get_rate_limiter() -> RateLimiter:
"""获取限流器实例"""
global _rate_limiter
@@ -167,6 +173,7 @@ def get_rate_limiter() -> RateLimiter:
# 限流装饰器(用于函数级别限流)
def rate_limit(requests_per_minute: int = 60, key_func: Callable | None = None) -> None:
"""
限流装饰器
@@ -209,5 +216,6 @@ def rate_limit(requests_per_minute: int = 60, key_func: Callable | None = None)
return decorator
class RateLimitExceeded(Exception):
"""限流异常"""