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

Function _is_async_callable

src/anthropic/_middleware.py:73–82  ·  view source on GitHub ↗

Whether calling the given object returns a coroutine. Unlike `inspect.iscoroutinefunction(obj)` this also handles class instances that define an async `__call__` method.

(obj: object)

Source from the content-addressed store, hash-verified

71
72
73def _is_async_callable(obj: object) -> bool:
74 """Whether calling the given object returns a coroutine.
75
76 Unlike `inspect.iscoroutinefunction(obj)` this also handles class instances
77 that define an async `__call__` method.
78 """
79 if inspect.iscoroutinefunction(obj):
80 return True
81 call = getattr(obj, "__call__", None) # noqa: B004
82 return call is not None and inspect.iscoroutinefunction(call)
83
84
85def validate_sync_middleware(middleware: Iterable[MiddlewareInput]) -> None:

Callers 2

validate_sync_middlewareFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected