From a5f119963a56034c325a69a274f2772cd3d397ba Mon Sep 17 00:00:00 2001 From: Yurii Motov Date: Wed, 5 Nov 2025 10:47:54 +0100 Subject: [PATCH] Remove unused import, make changes in `models.py` --- fastapi/dependencies/models.py | 27 ++++++++++++++++++--------- fastapi/dependencies/utils.py | 1 - 2 files changed, 18 insertions(+), 10 deletions(-) diff --git a/fastapi/dependencies/models.py b/fastapi/dependencies/models.py index d6359c0f5..e8dc38b80 100644 --- a/fastapi/dependencies/models.py +++ b/fastapi/dependencies/models.py @@ -1,7 +1,7 @@ import inspect import sys from dataclasses import dataclass, field -from functools import cached_property +from functools import cached_property, partial from typing import Any, Callable, List, Optional, Sequence, Union from fastapi._compat import ModelField @@ -53,25 +53,34 @@ class Dependant: @cached_property def is_gen_callable(self) -> bool: - if inspect.isgeneratorfunction(self.call): + use_call: Any = self.call + if isinstance(self.call, partial): + use_call = self.call.func + if inspect.isgeneratorfunction(use_call): return True - dunder_call = getattr(self.call, "__call__", None) # noqa: B004 + dunder_call = getattr(use_call, "__call__", None) # noqa: B004 return inspect.isgeneratorfunction(dunder_call) @cached_property def is_async_gen_callable(self) -> bool: - if inspect.isasyncgenfunction(self.call): + use_call: Any = self.call + if isinstance(self.call, partial): + use_call = self.call.func + if inspect.isasyncgenfunction(use_call): return True - dunder_call = getattr(self.call, "__call__", None) # noqa: B004 + dunder_call = getattr(use_call, "__call__", None) # noqa: B004 return inspect.isasyncgenfunction(dunder_call) @cached_property def is_coroutine_callable(self) -> bool: - if inspect.isroutine(self.call): - return iscoroutinefunction(self.call) - if inspect.isclass(self.call): + use_call: Any = self.call + if isinstance(self.call, partial): + use_call = self.call.func + if inspect.isroutine(use_call): + return iscoroutinefunction(use_call) + if inspect.isclass(use_call): return False - dunder_call = getattr(self.call, "__call__", None) # noqa: B004 + dunder_call = getattr(use_call, "__call__", None) # noqa: B004 return iscoroutinefunction(dunder_call) @cached_property diff --git a/fastapi/dependencies/utils.py b/fastapi/dependencies/utils.py index 25f377efa..c5c6b69bb 100644 --- a/fastapi/dependencies/utils.py +++ b/fastapi/dependencies/utils.py @@ -2,7 +2,6 @@ import inspect from contextlib import AsyncExitStack, contextmanager from copy import copy, deepcopy from dataclasses import dataclass -from functools import partial from typing import ( Any, Callable,