resolved RESOLVED PASS · 27 tool calls · 0 s · fastapi/fastapi
♻️ Make the result of `Depends()` and `Security()` hashable, as a workaround for other tools interacting with these internal parts ♻️ Make the result of `Depends()` and `Security()` hashable, as a workaround for other tools interacting with these internal parts --- This comes from https://github.com/fastapi/fastapi/pull/14320 As a note, FastAPI doesn't really have official support for extending its internals in ways that are not documented in the docs. So this is not a long-term commitment to keep some specific behavior, but a quick workaround to make things easier for current tools that interact with FastAPI internals in some way. --- At some point in the future, I'll refactor the internals of FastAPI to make them more explicitly private, and then also figure out the right ways to expose any points of connection with external components that currently need to interact with the internals in some way, and formalize that better. --- Before that, I need to handle a few issues, bugs, features, refactors, deprecations, etc. And then I'll be able to come back to this idea of figuring out how and what to expose. :nerd_face:
| # | Tool | Arguments | Result |
|---|---|---|---|
| No trace captured. | |||
diff --git a/fastapi/params.py b/fastapi/params.py
index 6a58d580..2645c671 100644
--- a/fastapi/params.py
+++ b/fastapi/params.py
@@ -762,13 +762,17 @@ class File(Form): # type: ignore[misc]
)
-@dataclass
+@dataclass(frozen=True)
class Depends:
dependency: Optional[Callable[..., Any]] = None
use_cache: bool = True
scope: Union[Literal["function", "request"], None] = None
-@dataclass
+@dataclass(frozen=True)
class Security(Depends):
scopes: Optional[Sequence[str]] = None
+
+ def __post_init__(self) -> None:
+ if self.scopes is not None:
+ object.__setattr__(self, "scopes", tuple(self.scopes))
. [100%] 1 passed in 0.49s