MCPcopy
hub / github.com/anthropics/anthropic-sdk-python / validate_async_middleware

Function validate_async_middleware

src/anthropic/_middleware.py:107–126  ·  view source on GitHub ↗
(middleware: Iterable[MiddlewareInput])

Source from the content-addressed store, hash-verified

105
106
107def 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 )

Callers 1

__init__Method · 0.85

Calls 2

_middleware_nameFunction · 0.85
_is_async_callableFunction · 0.85

Tested by

no test coverage detected