TL;DR: Fix is available here: #58, pls merge.
First Check
Commit to Help
Example Code
importasynciofromtypingimportOptionalfromsqlalchemy.ext.asyncioimportcreate_async_enginefromsqlmodelimportField, SQLModel, selectfromsqlmodel.ext.asyncio.sessionimportAsyncSessionclassHero(SQLModel, table=True):
id: Optional[int] =Field(default=None, primary_key=True)
name: strsecret_name: strage: Optional[int] =Noneasyncdefmain() ->None:
engine=create_async_engine("sqlite+aiosqlite:///database.db")
asyncwithengine.begin() asconn:
awaitconn.run_sync(SQLModel.metadata.create_all)
asyncwithAsyncSession(engine) assession:
session.add(Hero(name="Spider-Boy", secret_name="Pedro Parqueador"))
awaitsession.commit()
asyncwithAsyncSession(engine) assession:
statement=select(Hero).where(Hero.name=="Spider-Boy")
h= (awaitsession.exec(statement)).first()
print(h) # name='Spider-Boy' id=2 age=None secret_name='Pedro Parqueador'asyncio.run(main())Description
First of all, props for yet another amazing library! 🎉❤️
I didn't dive into source code yet to verify that I'm doing the right thing, but in the runtime the snippet behaves as expected. However that's not the case with static analysis:
Mypy gives this error:
$ mypymodel.py# Mypy Version: 0.910 model.py:21: error: Argument1to"exec"of"AsyncSession"hasincompatibletype"SelectOfScalar[Hero]"; expected"Union[Select[<nothing>], Executable[<nothing>]]"Found1errorin1file (checked1sourcefile)
PyCharm fails to derive session variable type:

May be related to PY-29891!
Even when session type explicitly stated, PyCharm still struggles to provide same experience as with sync Session

I acknowledge that the issue might be caused Typing/MyPy/PyCharm limitations.
I would be happy to work towards fixing the issue in my free time. Ideally, for that I'd want some clarification and thoughts regarding the issue.
Operating System
macOS 11.4 (20F71)
SQLModel Version
0.0.4
Python Version
Python 3.9.6
Additional Context
- Before running code snipped, you need to
pip install aiosqlite sqlalchemy[asyncio] - Mypy Version:
0.910 - PyCharm Version:
PyCharm 2021.1.3 (Professional Edition) Build #PY-211.7628.24, built on June 30, 2021
TL;DR: Fix is available here: #58, pls merge.
First Check
Commit to Help
Example Code
Description
First of all, props for yet another amazing library! 🎉❤️
I didn't dive into source code yet to verify that I'm doing the right thing, but in the runtime the snippet behaves as expected. However that's not the case with static analysis:
Mypy gives this error:
PyCharm fails to derive

sessionvariable type:May be related to PY-29891!
Even when

sessiontype explicitly stated, PyCharm still struggles to provide same experience as with syncSessionI acknowledge that the issue might be caused Typing/MyPy/PyCharm limitations.
I would be happy to work towards fixing the issue in my free time. Ideally, for that I'd want some clarification and thoughts regarding the issue.
Operating System
macOS 11.4 (20F71)
SQLModel Version
0.0.4
Python Version
Python 3.9.6
Additional Context
pip install aiosqlite sqlalchemy[asyncio]0.910PyCharm 2021.1.3 (Professional Edition) Build #PY-211.7628.24, built on June 30, 2021