refac: modernize type annotations (PEP 604 / PEP 585)

This commit is contained in:
Timothy Jaeryang Baek committed 2026-05-12 17:10:15 +09:00
1 parent a59c967d7e
commit 6d0295588e
197 files changed
+3265 -3488

No files matched your search

+14 -13
View File
@@ -1,12 +1,13 @@
from __future__ import annotations
import time
import uuid
from typing import Optional
from sqlalchemy import select, delete
from sqlalchemy.ext.asyncio import AsyncSession
from open_webui.internal.db import Base, get_async_db_context
from pydantic import BaseModel, ConfigDict
from sqlalchemy import BigInteger, Column, String, Text
from sqlalchemy import BigInteger, Column, String, Text, delete, select
from sqlalchemy.ext.asyncio import AsyncSession
####################
# Memory DB Schema
@@ -45,8 +46,8 @@ class MemoriesTable:
self,
user_id: str,
content: str,
db: Optional[AsyncSession] = None,
) -> Optional[MemoryModel]:
db: AsyncSession | None = None,
) -> MemoryModel | None:
async with get_async_db_context(db) as db:
id = str(uuid.uuid4())
@@ -73,8 +74,8 @@ class MemoriesTable:
id: str,
user_id: str,
content: str,
db: Optional[AsyncSession] = None,
) -> Optional[MemoryModel]:
db: AsyncSession | None = None,
) -> MemoryModel | None:
async with get_async_db_context(db) as db:
try:
memory = await db.get(Memory, id)
@@ -90,7 +91,7 @@ class MemoriesTable:
except Exception:
return None
async def get_memories(self, db: Optional[AsyncSession] = None) -> list[MemoryModel]:
async def get_memories(self, db: AsyncSession | None = None) -> list[MemoryModel]:
async with get_async_db_context(db) as db:
try:
result = await db.execute(select(Memory))
@@ -99,7 +100,7 @@ class MemoriesTable:
except Exception:
return None
async def get_memories_by_user_id(self, user_id: str, db: Optional[AsyncSession] = None) -> list[MemoryModel]:
async def get_memories_by_user_id(self, user_id: str, db: AsyncSession | None = None) -> list[MemoryModel]:
async with get_async_db_context(db) as db:
try:
result = await db.execute(select(Memory).filter_by(user_id=user_id))
@@ -108,7 +109,7 @@ class MemoriesTable:
except Exception:
return None
async def get_memory_by_id(self, id: str, db: Optional[AsyncSession] = None) -> Optional[MemoryModel]:
async def get_memory_by_id(self, id: str, db: AsyncSession | None = None) -> MemoryModel | None:
async with get_async_db_context(db) as db:
try:
memory = await db.get(Memory, id)
@@ -116,7 +117,7 @@ class MemoriesTable:
except Exception:
return None
async def delete_memory_by_id(self, id: str, db: Optional[AsyncSession] = None) -> bool:
async def delete_memory_by_id(self, id: str, db: AsyncSession | None = None) -> bool:
async with get_async_db_context(db) as db:
try:
await db.execute(delete(Memory).filter_by(id=id))
@@ -127,7 +128,7 @@ class MemoriesTable:
except Exception:
return False
async def delete_memories_by_user_id(self, user_id: str, db: Optional[AsyncSession] = None) -> bool:
async def delete_memories_by_user_id(self, user_id: str, db: AsyncSession | None = None) -> bool:
async with get_async_db_context(db) as db:
try:
await db.execute(delete(Memory).filter_by(user_id=user_id))
@@ -137,7 +138,7 @@ class MemoriesTable:
except Exception:
return False
async def delete_memory_by_id_and_user_id(self, id: str, user_id: str, db: Optional[AsyncSession] = None) -> bool:
async def delete_memory_by_id_and_user_id(self, id: str, user_id: str, db: AsyncSession | None = None) -> bool:
async with get_async_db_context(db) as db:
try:
memory = await db.get(Memory, id)