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

Function validate_sync_middleware

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

Source from the content-addressed store, hash-verified

83
84
85def validate_sync_middleware(middleware: Iterable[MiddlewareInput]) -> None:
86 for entry in middleware:
87 if isinstance(entry, Middleware):
88 if type(entry).handle is Middleware.handle:
89 raise TypeError(
90 f"middleware {_middleware_name(entry)} does not implement `handle()`; "
91 "the synchronous client requires sync-capable middleware"
92 )
93 if inspect.iscoroutinefunction(type(entry).handle):
94 raise TypeError(
95 f"middleware {_middleware_name(entry)} defines `handle()` as an async function; "
96 "the synchronous client requires `handle()` to be a sync function"
97 )
98 elif not callable(entry):
99 raise TypeError(f"middleware {_middleware_name(entry)} is not callable")
100 elif _is_async_callable(entry):
101 raise TypeError(
102 f"middleware {_middleware_name(entry)} is an async function; "
103 "the synchronous client requires sync middleware functions"
104 )
105
106
107def validate_async_middleware(middleware: Iterable[MiddlewareInput]) -> None:

Callers 1

__init__Method · 0.85

Calls 2

_middleware_nameFunction · 0.85
_is_async_callableFunction · 0.85

Tested by

no test coverage detected