MCPcopy
hub / github.com/encode/starlette / test_handlers_annotations

Function test_handlers_annotations

tests/test_exceptions.py:210–224  ·  view source on GitHub ↗

Check that async exception handlers are accepted by type checkers. We annotate the handlers' exceptions with plain `Exception` to avoid variance issues when using other exception types.

()

Source from the content-addressed store, hash-verified

208
209
210def test_handlers_annotations() -> None:
211 """Check that async exception handlers are accepted by type checkers.
212
213 We annotate the handlers' exceptions with plain `Exception` to avoid variance issues
214 when using other exception types.
215 """
216
217 async def async_catch_all_handler(request: Request, exc: Exception) -> JSONResponse:
218 raise NotImplementedError
219
220 def sync_catch_all_handler(request: Request, exc: Exception) -> JSONResponse:
221 raise NotImplementedError
222
223 ExceptionMiddleware(router, handlers={Exception: sync_catch_all_handler})
224 ExceptionMiddleware(router, handlers={Exception: async_catch_all_handler})

Callers

nothing calls this directly

Calls 1

ExceptionMiddlewareClass · 0.90

Tested by

no test coverage detected