Skip to content

Improving Static Typing Support #147

@jd-solanki

Description

@jd-solanki

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

Screenshots
image

Additional context
PR: None

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions