From 458ce65ef9c02804b318c4b63022248ce5f0774e Mon Sep 17 00:00:00 2001 From: Adeniran John Date: Thu, 6 Nov 2025 10:29:33 +0100 Subject: [PATCH] Fix: allow internal scope kwarg in Depends while keeping validation --- fastapi/params.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/fastapi/params.py b/fastapi/params.py index 9950ac377..52a5cbbea 100644 --- a/fastapi/params.py +++ b/fastapi/params.py @@ -765,7 +765,11 @@ class Depends: scope: Union[Literal["function", "request"], None] = None def __init__( - self, dependency: Optional[Callable[..., Any]] = None, *, use_cache: bool = True + self, + dependency: Optional[Callable[..., Any]] = None, + *, + use_cache: bool = True, + scope: Union[Literal["function", "request"], None] = None, ): # Validate that dependency is used correctly if dependency is not None: @@ -800,6 +804,7 @@ class Depends: self.dependency = dependency self.use_cache = use_cache + self.scope = scope def __repr__(self) -> str: attr = getattr(self.dependency, "__name__", type(self.dependency).__name__)