Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improving Static Typing Support #147

Open
jd-solanki opened this issue Aug 8, 2024 · 0 comments
Open

Improving Static Typing Support #147

jd-solanki opened this issue Aug 8, 2024 · 0 comments

Comments

@jd-solanki
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant