(middleware: Iterable[MiddlewareInput])
| 105 | |
| 106 | |
| 107 | def validate_async_middleware(middleware: Iterable[MiddlewareInput]) -> None: |
| 108 | for entry in middleware: |
| 109 | if isinstance(entry, Middleware): |
| 110 | if type(entry).handle_async is Middleware.handle_async: |
| 111 | raise TypeError( |
| 112 | f"middleware {_middleware_name(entry)} does not implement `handle_async()`; " |
| 113 | "the asynchronous client requires async-capable middleware" |
| 114 | ) |
| 115 | if not inspect.iscoroutinefunction(type(entry).handle_async): |
| 116 | raise TypeError( |
| 117 | f"middleware {_middleware_name(entry)} defines `handle_async()` as a sync function; " |
| 118 | "the asynchronous client requires `handle_async()` to be an async function" |
| 119 | ) |
| 120 | elif not callable(entry): |
| 121 | raise TypeError(f"middleware {_middleware_name(entry)} is not callable") |
| 122 | elif not _is_async_callable(entry): |
| 123 | raise TypeError( |
| 124 | f"middleware {_middleware_name(entry)} is not an async function; " |
| 125 | "the asynchronous client requires async middleware functions" |
| 126 | ) |
no test coverage detected