Quellcodebibliothek Statistik Leitseite products/Sources/formale Sprachen/Python/SDK/examples/stories/parallel_calls/     Datei vom 5.10.2026 mit Größe 1 kB image not shown  

Impressum _callable_inspection.py   Sprache: Python

 

"""Callable inspection utilities.

Adapted from Starlette's `is_async_callable` implementation.
https://github.com/encode/starlette/blob/main/starlette/_utils.py
"
""

from __future__ import annotations

import functools
import inspect
from collections.abc import Awaitable, Callable
from typing import Any, TypeGuard, TypeVar, overload

T = TypeVar("T")

AwaitableCallable = Callable[..., Awaitable[T]]


@overload
def is_async_callable(obj: AwaitableCallable[T]) -> TypeGuard[AwaitableCallable[T]]: ...


@overload
def is_async_callable(obj: Any) -> TypeGuard[AwaitableCallable[Any]]: ...


def is_async_callable(obj: Any) -> Any:
    while isinstance(obj, functools.partial):  # pragma: lax no cover
        obj = obj.func

    return inspect.iscoroutinefunction(obj) or (
        callable(obj) and inspect.iscoroutinefunction(getattr(obj, "__call__", None))
    )

Messung
CHZG
919810096

¤ Dauer der Verarbeitung: 0.20 Sekunden  ¤

*Bot Zugriff