refactor(project): make pyright & ruff happy
This commit is contained in:
@@ -40,15 +40,11 @@ engine = create_async_engine(
|
||||
redis_client = redis.from_url(settings.redis_url, decode_responses=True)
|
||||
|
||||
# Redis 消息缓存连接 (db1) - 使用同步客户端在线程池中执行
|
||||
redis_message_client = sync_redis.from_url(
|
||||
settings.redis_url, decode_responses=True, db=1
|
||||
)
|
||||
redis_message_client = sync_redis.from_url(settings.redis_url, decode_responses=True, db=1)
|
||||
|
||||
|
||||
# 数据库依赖
|
||||
db_session_context: ContextVar[AsyncSession | None] = ContextVar(
|
||||
"db_session_context", default=None
|
||||
)
|
||||
db_session_context: ContextVar[AsyncSession | None] = ContextVar("db_session_context", default=None)
|
||||
|
||||
|
||||
async def get_db():
|
||||
|
||||
@@ -25,7 +25,5 @@ async def get_fetcher() -> Fetcher:
|
||||
if refresh_token:
|
||||
fetcher.refresh_token = str(refresh_token)
|
||||
if not fetcher.access_token or not fetcher.refresh_token:
|
||||
logger.opt(colors=True).info(
|
||||
f"Login to initialize fetcher: <y>{fetcher.authorize_url}</y>"
|
||||
)
|
||||
logger.opt(colors=True).info(f"Login to initialize fetcher: <y>{fetcher.authorize_url}</y>")
|
||||
return fetcher
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
from __future__ import annotations
|
||||
|
||||
from datetime import UTC
|
||||
from typing import cast
|
||||
|
||||
from apscheduler.schedulers.asyncio import AsyncIOScheduler
|
||||
|
||||
@@ -16,7 +17,7 @@ def get_scheduler() -> AsyncIOScheduler:
|
||||
global scheduler
|
||||
if scheduler is None:
|
||||
init_scheduler()
|
||||
return scheduler # pyright: ignore[reportReturnType]
|
||||
return cast(AsyncIOScheduler, scheduler)
|
||||
|
||||
|
||||
def start_scheduler():
|
||||
|
||||
@@ -70,9 +70,7 @@ async def v1_authorize(
|
||||
if not api_key:
|
||||
raise HTTPException(status_code=401, detail="Missing API key")
|
||||
|
||||
api_key_record = (
|
||||
await db.exec(select(V1APIKeys).where(V1APIKeys.key == api_key))
|
||||
).first()
|
||||
api_key_record = (await db.exec(select(V1APIKeys).where(V1APIKeys.key == api_key))).first()
|
||||
if not api_key_record:
|
||||
raise HTTPException(status_code=401, detail="Invalid API key")
|
||||
|
||||
@@ -98,9 +96,7 @@ async def get_current_user(
|
||||
security_scopes: SecurityScopes,
|
||||
token_pw: Annotated[str | None, Depends(oauth2_password)] = None,
|
||||
token_code: Annotated[str | None, Depends(oauth2_code)] = None,
|
||||
token_client_credentials: Annotated[
|
||||
str | None, Depends(oauth2_client_credentials)
|
||||
] = None,
|
||||
token_client_credentials: Annotated[str | None, Depends(oauth2_client_credentials)] = None,
|
||||
) -> User:
|
||||
"""获取当前认证用户"""
|
||||
token = token_pw or token_code or token_client_credentials
|
||||
@@ -119,9 +115,7 @@ async def get_current_user(
|
||||
if not is_client:
|
||||
for scope in security_scopes.scopes:
|
||||
if scope not in token_record.scope.split(","):
|
||||
raise HTTPException(
|
||||
status_code=403, detail=f"Insufficient scope: {scope}"
|
||||
)
|
||||
raise HTTPException(status_code=403, detail=f"Insufficient scope: {scope}")
|
||||
|
||||
user = (await db.exec(select(User).where(User.id == token_record.user_id))).first()
|
||||
if not user:
|
||||
|
||||
Reference in New Issue
Block a user