Skip to content

Commit

Permalink
Fix types in lifespan examples (encode#2123)
Browse files Browse the repository at this point in the history
  • Loading branch information
alex-oleshkevich authored Apr 17, 2023
1 parent 597071c commit ab296fd
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions docs/lifespan.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ from typing import TypedDict

import httpx
from starlette.applications import Starlette
from starlette.requests import Request
from starlette.responses import PlainTextResponse
from starlette.routing import Route

Expand All @@ -52,12 +53,12 @@ class State(TypedDict):


@contextlib.asynccontextmanager
async def lifespan(app: Starlette) -> State:
async def lifespan(app: Starlette) -> typing.AsyncIterator[State]:
async with httpx.AsyncClient() as client:
yield {"http_client": client}


async def homepage(request):
async def homepage(request: Request) -> PlainTextResponse:
client = request.state.http_client
response = await client.get("https://www.example.com")
return PlainTextResponse(response.text)
Expand Down

0 comments on commit ab296fd

Please sign in to comment.