MCPcopy
hub / github.com/fastapi/fastapi / _wrap_gen_lifespan_context

Function _wrap_gen_lifespan_context

fastapi/routing.py:208–222  ·  view source on GitHub ↗

Wrap a generator-based lifespan context into an async context manager. This is vendored from Starlette to avoid importing private symbols.

(
    lifespan_context: Callable[[Any], Generator[Any, Any, Any]],
)

Source from the content-addressed store, hash-verified

206
207# Vendored from starlette.routing to avoid importing private symbols
208def _wrap_gen_lifespan_context(
209 lifespan_context: Callable[[Any], Generator[Any, Any, Any]],
210) -> Callable[[Any], AbstractAsyncContextManager[Any]]:
211 """
212 Wrap a generator-based lifespan context into an async context manager.
213
214 This is vendored from Starlette to avoid importing private symbols.
215 """
216 cmgr = contextlib.contextmanager(lifespan_context)
217
218 @functools.wraps(cmgr)
219 def wrapper(app: Any) -> _AsyncLiftContextManager[Any]:
220 return _AsyncLiftContextManager(cmgr(app))
221
222 return wrapper
223
224
225def _merge_lifespan_context(

Callers 1

__init__Method · 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…