From 6819c5d1ad079c8b263924f4c6b761bd6873fdc1 Mon Sep 17 00:00:00 2001 From: Igor Benav Date: Sun, 15 Sep 2024 02:24:42 -0300 Subject: [PATCH] Deprecation for handling Depends, now only callable in _inject_dependencies --- fastcrud/endpoint/helper.py | 41 ++++++++----------------------------- 1 file changed, 8 insertions(+), 33 deletions(-) diff --git a/fastcrud/endpoint/helper.py b/fastcrud/endpoint/helper.py index 4971026..2f16f72 100644 --- a/fastcrud/endpoint/helper.py +++ b/fastcrud/endpoint/helper.py @@ -1,6 +1,5 @@ import inspect from typing import Optional, Union, Annotated, Sequence, Callable, TypeVar, Any -import warnings from pydantic import BaseModel, Field from pydantic.functional_validators import field_validator @@ -127,42 +126,18 @@ def _extract_unique_columns( return unique_columns -def _temporary_dependency_handling( - funcs: Optional[Sequence[Callable]] = None, -) -> Union[Sequence[params.Depends], None]: # pragma: no cover - """ - Checks if any function in the provided sequence is an instance of params.Depends. - Issues a deprecation warning once if such instances are found, and returns the sequence if any params.Depends are found. - - Args: - funcs: Optional sequence of callables or params.Depends instances. - """ - if funcs is not None: - if any(isinstance(func, params.Depends) for func in funcs): - warnings.warn( - "Passing a function wrapped in `Depends` directly to dependency handlers is deprecated and will be removed in version 0.15.0.", - DeprecationWarning, - stacklevel=2, - ) - return [ - func if isinstance(func, params.Depends) else Depends(func) - for func in funcs - ] - return None - - def _inject_dependencies( funcs: Optional[Sequence[Callable]] = None, ) -> Optional[Sequence[params.Depends]]: """Wraps a list of functions in FastAPI's Depends.""" - temp_handling = _temporary_dependency_handling(funcs) - if temp_handling is not None: # pragma: no cover - return temp_handling - - if funcs is not None: - return [Depends(func) for func in funcs] - - return None + if funcs is None: + return None + + for func in funcs: + if not callable(func): + raise TypeError(f"All dependencies must be callable. Got {type(func)} instead.") + + return [Depends(func) for func in funcs] def _apply_model_pk(**pkeys: dict[str, type]):