INNER CODE UNIT · Python

_has_depends

JasperSui/fastapi-injectable · src/fastapi_injectable/main.py:88

def _has_depends(param: inspect.Parameter) -> bool:
    """Check if a parameter has a Depends() annotation (either via Annotated metadata or as default)."""
    # Check Annotated[Type, Depends(...)] style
    if get_origin(param.annotation) is Annotated:
        for metadata in get_args(param.annotation)[1:]:
            if isinstance(metadata, fastapi.params.Depends):
                return True
    # Check default=Depends(...) style
    return isinstance(param.default, fastapi.params.Depends)


def _build_dependency_only_callable(
    func: Callable[..., Any],
) -> Callable[..., Any]:
    """Create a callable with only Depends() parameters in its signature.

    This prevents FastAPI's get_dependant from trying to parse non-dependency
    parameters (e.g. ``self``, Celery's bound ``task``) as query/body params,

View source record →

📰 Research Paper
Loading…
⏳ Fetching content…