From 1202318cb8b82f507908e2b1416c77b239c78f2a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebasti=C3=A1n=20Ram=C3=ADrez?= Date: Tue, 2 Dec 2025 21:50:14 +0100 Subject: [PATCH] =?UTF-8?q?=E2=99=BB=EF=B8=8F=20Move=20partial=20extractio?= =?UTF-8?q?n=20logic=20to=20Dependant.=5Funwrapped=5Fcall?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- fastapi/dependencies/models.py | 30 ++++++++++++------------------ 1 file changed, 12 insertions(+), 18 deletions(-) diff --git a/fastapi/dependencies/models.py b/fastapi/dependencies/models.py index f544dd018..2a4d9a010 100644 --- a/fastapi/dependencies/models.py +++ b/fastapi/dependencies/models.py @@ -79,38 +79,32 @@ class Dependant: def _unwrapped_call(self) -> Any: if self.call is None: return self.call # pragma: no cover - return inspect.unwrap(self.call) + unwrapped = inspect.unwrap(self.call) + if isinstance(unwrapped, partial): + unwrapped = unwrapped.func + return unwrapped @cached_property def is_gen_callable(self) -> bool: - use_call: Any = self._unwrapped_call - if isinstance(use_call, partial): - use_call = use_call.func - if inspect.isgeneratorfunction(use_call): + if inspect.isgeneratorfunction(self._unwrapped_call): return True - dunder_call = getattr(use_call, "__call__", None) # noqa: B004 + dunder_call = getattr(self._unwrapped_call, "__call__", None) # noqa: B004 return inspect.isgeneratorfunction(dunder_call) @cached_property def is_async_gen_callable(self) -> bool: - use_call: Any = self._unwrapped_call - if isinstance(use_call, partial): - use_call = use_call.func - if inspect.isasyncgenfunction(use_call): + if inspect.isasyncgenfunction(self._unwrapped_call): return True - dunder_call = getattr(use_call, "__call__", None) # noqa: B004 + dunder_call = getattr(self._unwrapped_call, "__call__", None) # noqa: B004 return inspect.isasyncgenfunction(dunder_call) @cached_property def is_coroutine_callable(self) -> bool: - use_call: Any = self._unwrapped_call - if isinstance(use_call, partial): - use_call = use_call.func - if inspect.isroutine(use_call): - return iscoroutinefunction(use_call) - if inspect.isclass(use_call): + if inspect.isroutine(self._unwrapped_call): + return iscoroutinefunction(self._unwrapped_call) + if inspect.isclass(self._unwrapped_call): return False - dunder_call = getattr(use_call, "__call__", None) # noqa: B004 + dunder_call = getattr(self._unwrapped_call, "__call__", None) # noqa: B004 return iscoroutinefunction(dunder_call) @cached_property