Extract endpoint context with caching to avoid repeated file I/O.
(func: Any)
| 268 | |
| 269 | |
| 270 | def _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 | |
| 293 | async def serialize_response( |
no test coverage detected
searching dependent graphs…