Improving Static Typing Support
Opened this issue ยท 0 comments
jd-solanki commented
Describe the bug or question
Hi ๐๐ป
I can see oportunity to improve the typig for FastCRUD lib. I'll be listing type issues I encounter while using the FastCRUD and try to make PR as I get the time.
1. Using FastCRUD
& delete
gives partially unknow method
To Reproduce
minimal example
from fastcrud import FastCRUD
from sqlalchemy.orm import DeclarativeBase, MappedAsDataclass
from pydantic import BaseModel
from fastapi import FastAPI, Depends
from sqlalchemy.ext.asyncio import AsyncSession, async_sessionmaker, create_async_engine
from collections.abc import AsyncGenerator
# --- DB
class Base(DeclarativeBase, MappedAsDataclass): ...
class Chat(Base): ...
engine = create_async_engine("sqlite+aiosqlite:///asqlite.db")
async_session_maker = async_sessionmaker(bind=engine, expire_on_commit=False)
async def get_db() -> AsyncGenerator[AsyncSession, None]:
async with async_session_maker() as session:
yield session
# --- Schemas
class ChatCreate(BaseModel): ...
class ChatUpdate(BaseModel): ...
class ChatUpdateInternal(BaseModel): ...
class ChatDelete(BaseModel): ...
FastCRUDChat = FastCRUD[
Chat,
ChatCreate,
ChatUpdate,
ChatUpdateInternal,
ChatDelete,
]
chat_fastcrud = FastCRUDChat(Chat)
# --- FastAPI
app = FastAPI()
@app.delete("/chat/{id}")
async def delete_chat(id: int, db: AsyncSession = Depends(get_db)):
return await chat_fastcrud.delete(db, id=id) # ๐จ Type of "delete" is partially unknown
Description
There might be missing assignment of generic type
Additional context
PR: None