-
First Check
Commit to Help
Example Codefrom collections.abc import AsyncGenerator
from contextlib import asynccontextmanager
from fastapi import FastAPI
@asynccontextmanager
async def lifespan(_: FastAPI) -> AsyncGenerator[None, None]:
...
yield
...
app = FastAPI(lifespan=lifespan)DescriptionI have taken the example from the docs of the lifespan async context manager - new in 0.93 - shaved it down to the bare minimum, and added typing hints. When running this code through mypy-1.1.1 it complains about the type of the $ pipenv run mypy lifespan_example.py
Loading .env environment variables...
lifespan_example.py:14: error:
Argument "lifespan" to "FastAPI" has incompatible type
"Callable[[FastAPI], _AsyncGeneratorContextManager[None]]";
expected
"Union[Callable[[Starlette], AbstractAsyncContextManager[None]], Callable[[Starlette], AbstractAsyncContextManager[Mapping[str, Any]]], None]" [arg-type]
Found 1 error in 1 file (checked 1 source file)I am unsure whether this is an issue with FastAPI, mypy, contextlib, or me. 🤷 Operating SystemLinux Operating System DetailsUbuntu 20.04 running in WSL2. FastAPI Version0.94 Python Version3.10.8 Additional ContextNo response |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 2 replies
-
Beta Was this translation helpful? Give feedback.
-
|
As @adriangb said, this is an issue on Starlette's side. We'll be handling it over there. Thanks for the report. 🙏 |
Beta Was this translation helpful? Give feedback.
As @adriangb said, this is an issue on Starlette's side. We'll be handling it over there.
Thanks for the report. 🙏