Skip to content

Commit

Permalink
Cutefy Adrian's improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
Kludex committed Mar 5, 2023
1 parent c791251 commit f311c96
Showing 1 changed file with 4 additions and 6 deletions.
10 changes: 4 additions & 6 deletions starlette/routing.py
Original file line number Diff line number Diff line change
Expand Up @@ -679,22 +679,20 @@ async def lifespan(self, scope: Scope, receive: Receive, send: Send) -> None:
"""
started = False
app = scope.get("app")
state = scope.get("state")
await receive()
lifespan_needs_state = (
len(inspect.signature(self.lifespan_context).parameters) == 2
)
server_supports_state = "state" in scope
server_supports_state = state is not None
if lifespan_needs_state and not server_supports_state:
raise RuntimeError(
'This server does not support "state" in the lifespan scope.'
" Please try updating your ASGI server."
'The server does not support "state" in the lifespan scope.'
)
try:
lifespan_context: Lifespan
if lifespan_needs_state:
lifespan_context = functools.partial(
self.lifespan_context, state=scope["state"]
)
lifespan_context = functools.partial(self.lifespan_context, state=state)
else:
lifespan_context = typing.cast(StatelessLifespan, self.lifespan_context)
async with lifespan_context(app):
Expand Down

0 comments on commit f311c96

Please sign in to comment.