MCPcopy
hub / github.com/fastapi/fastapi / _merge_lifespan_context

Function _merge_lifespan_context

fastapi/routing.py:225–239  ·  view source on GitHub ↗
(
    original_context: Lifespan[Any], nested_context: Lifespan[Any]
)

Source from the content-addressed store, hash-verified

223
224
225def _merge_lifespan_context(
226 original_context: Lifespan[Any], nested_context: Lifespan[Any]
227) -> Lifespan[Any]:
228 @asynccontextmanager
229 async def merged_lifespan(
230 app: AppType,
231 ) -> AsyncIterator[Mapping[str, Any] | None]:
232 async with original_context(app) as maybe_original_state:
233 async with nested_context(app) as maybe_nested_state:
234 if maybe_nested_state is None and maybe_original_state is None:
235 yield None # old ASGI compatibility
236 else:
237 yield {**(maybe_nested_state or {}), **(maybe_original_state or {})}
238
239 return merged_lifespan # type: ignore[return-value] # ty: ignore[invalid-return-type]
240
241
242class _DefaultLifespan:

Callers 1

include_routerMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…