"with" code block in python don't recognise the "as" variable type

I use Python 11 with Intellij Ultimate and I have the following code:

async def get_all_user_tabs(user_id: str) -> list[Tab]:
    """Get all the tabs of a user."""
    async with get_db_session() as db_session:
        return await db_session.query(Tab).filter(Tab.user_id == user_id).all()

The get_db_session yields an AsyncIterator[AsyncSession] type:

@asynccontextmanager
async def get_db_session() -> AsyncIterator[AsyncSession]:
    """Get the database session."""
    try:
        async with _ASYNC_LOCAL_SESSION_MAKER() as session:
            yield session
    except SQLAlchemyError as e:
        _LOGGER.exception(e)
        raise

but the db_session is still of type Any.

 

 

Anyone knows how to resolve this?

0
1 comment

Hi Tamir Hen , this appears to be a known issue PY-70786. Please vote for it and feel free to comment. See https://intellij-support.jetbrains.com/hc/en-us/articles/207241135-How-to-follow-YouTrack-issues-and-receive-notifications if you are not familiar with YouTrack.

Apologies for the inconvenience.

0

Please sign in to leave a comment.