MCPcopy
hub / github.com/fastapi/fastapi / _extract_endpoint_context

Function _extract_endpoint_context

fastapi/routing.py:270–290  ·  view source on GitHub ↗

Extract endpoint context with caching to avoid repeated file I/O.

(func: Any)

Source from the content-addressed store, hash-verified

268
269
270def _extract_endpoint_context(func: Any) -> EndpointContext:
271 """Extract endpoint context with caching to avoid repeated file I/O."""
272 func_id = id(func)
273
274 if func_id in _endpoint_context_cache:
275 return _endpoint_context_cache[func_id]
276
277 try:
278 ctx: EndpointContext = {}
279
280 if (source_file := inspect.getsourcefile(func)) is not None:
281 ctx["file"] = source_file
282 if (line_number := inspect.getsourcelines(func)[1]) is not None:
283 ctx["line"] = line_number
284 if (func_name := getattr(func, "__name__", None)) is not None:
285 ctx["function"] = func_name
286 except Exception:
287 ctx = EndpointContext()
288
289 _endpoint_context_cache[func_id] = ctx
290 return ctx
291
292
293async def serialize_response(

Callers 1

appFunction · 0.85

Calls 1

EndpointContextClass · 0.90

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…