resolved RESOLVED PASS · 11 tool calls · 43 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 |
|---|---|---|---|
| 1 | run_command | {
"command": "grep -rn \"class Depends\" fastapi | head -20"
} | {"status": "ok", "stdout": "fastapi/params.py:766:class Depends:\n", "stderr": "", "exit_code": 0}full{"status": "ok", "stdout": "fastapi/params.py:766:class Depends:\n", "stderr": "", "exit_code": 0} |
| 2 | read_file | {
"filepath": "fastapi/params.py",
"start_line": 766
} | {"status": "ok", "filepath": "fastapi/params.py", "content": "class Depends:\n dependency: Optional[Callable[..., Any]] = None\n use_cache: bool = True\n scope:full{"status": "ok", "filepath": "fastapi/params.py", "content": "class Depends:\n dependency: Optional[Callable[..., Any]] = None\n use_cache: bool = True\n scope: Union[Literal[\"function\", \"request\"], None] = None\n\n\n@dataclass\nclass Security(Depends):\n scopes: Optional[Sequence[str]] = None", "start_line": 766, "end_line": 774, "total_lines": 774, "is_truncated": false} |
| 3 | read_file | {
"filepath": "fastapi/params.py",
"start_line": 766,
"end_line": 774
} | {"status": "ok", "filepath": "fastapi/params.py", "content": "class Depends:\n dependency: Optional[Callable[..., Any]] = None\n use_cache: bool = True\n scope:full{"status": "ok", "filepath": "fastapi/params.py", "content": "class Depends:\n dependency: Optional[Callable[..., Any]] = None\n use_cache: bool = True\n scope: Union[Literal[\"function\", \"request\"], None] = None\n\n\n@dataclass\nclass Security(Depends):\n scopes: Optional[Sequence[str]] = None", "start_line": 766, "end_line": 774, "total_lines": 774, "is_truncated": false} |
| 4 | run_command | {
"command": "python3 -c \"from fastapi.params import Depends, Security; d1 = Depends(); d2 = Depends(); print(hash(d1)); print(hash(d2))\""
} | {"status": "error", "error_type": "CommandError", "error_message": "Traceback (most recent call last):\n File \"<string>\", line 1, in <module>\n from fastapi.pfull{"status": "error", "error_type": "CommandError", "error_message": "Traceback (most recent call last):\n File \"<string>\", line 1, in <module>\n from fastapi.params import Depends, Security; d1 = Depends(); d2 = Depends(); print(hash(d1)); print(hash(d2))\n ~~~~^^^^\nTypeError: unhashable type: 'Depends'\n", "details": {"stdout": "", "stderr": "Traceback (most recent call last):\n File \"<string>\", line 1, in <module>\n from fastapi.params import Depends, Security; d1 = Depends(); d2 = Depends(); print(hash(d1)); print(hash(d2))\n ~~~~^^^^\nTypeError: unhashable type: 'Depends'\n", "exit_code": 1}} |
| 5 | edit_file | {
"filepath": "fastapi/params.py",
"new_string": "@dataclass(frozen=True)\nclass Depends:\n dependency: Optional[Callable[..., Any]] = None\n use_cache: bool = True\n scope: Union[Literal[\"function\", \"request\"], None] = None\n\n\n\n@dataclass(frozen=True)\nclass Security(Depends):\n scopes: Optional[Sequence[str]] = None",
"old_string": "class Depends:\n dependency: Optional[Callable[..., Any]] = None\n use_cache: bool = True\n scope: Union[Literal[\"function\", \"request\"], None] = None\n\n\n@dataclass\nclass Security(Depends):\n scopes: Optional[Sequence[str]] = None"
} | {"status": "ok", "filepath": "fastapi/params.py", "occurrences": 1, "strategy": "exact", "diff": "--- a/fastapi/params.py\n+++ b/fastapi/params.py\n@@ -763,12 +full{"status": "ok", "filepath": "fastapi/params.py", "occurrences": 1, "strategy": "exact", "diff": "--- a/fastapi/params.py\n+++ b/fastapi/params.py\n@@ -763,12 +763,14 @@\n \n \n @dataclass\n+@dataclass(frozen=True)\n class Depends:\n dependency: Optional[Callable[..., Any]] = None\n use_cache: bool = True\n scope: Union[Literal[\"function\", \"request\"], None] = None\n \n \n-@dataclass\n+\n+@dataclass(frozen=True)\n class Security(Depends):\n scopes: Optional[Sequence[str]] = None\n", "is_truncated": false} |
| 6 | run_command | {
"command": "python3 -c \"from fastapi.params import Depends, Security; d1 = Depends(); d2 = Depends(); print(hash(d1)); print(hash(d2)); s1 = Security(); s2 = Security(); print(hash(s1)); print(hash(s2))\""
} | {"status": "error", "error_type": "CommandError", "error_message": "Traceback (most recent call last):\n File \"<string>\", line 1, in <module>\n from fastapi.pfull{"status": "error", "error_type": "CommandError", "error_message": "Traceback (most recent call last):\n File \"<string>\", line 1, in <module>\n from fastapi.params import Depends, Security; d1 = Depends(); d2 = Depends(); print(hash(d1)); print(hash(d2)); s1 = Security(); s2 = Security(); print(hash(s1)); print(hash(s2))\n ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n File \"/private/workspace/fastapi/__init__.py\", line 7, in <module>\n from .applications import FastAPI as FastAPI\n File \"/private/workspace/fastapi/applications.py\", line 17, in <module>\n from fastapi import routing\n File \"/private/workspace/fastapi/routing.py\", line 28, in <module>\n from fastapi import params, temp_pydantic_v1_params\n File \"/private/workspace/fastapi/params.py\", line 774, in <module>\n @dataclass(frozen=True)\n ~~~~~~~~~^^^^^^^^^^^^^\n File \"/Users/jp/.local/share/uv/python/cpython-3.13.15-macos-aarch64-none/lib/python3.13/dataclasses.py\", line 1344, in wrap\n return _process_class(cls, init, repr, eq, order, unsafe_hash,\n frozen, match_args, kw_only, slots,\n weakref_slot)\n File \"/Users/jp/.local/share/uv/python/cpython-3.13.15-macos-aarch64-none/lib/python3.13/dataclasses.py\", line 1043, in _process_class\n raise TypeError('cannot inherit frozen dataclass from a '\n 'non-frozen one')\nTypeError: cannot inherit frozen dataclass from a non-frozen one\n", "details": {"stdout": "", "stderr": "Traceback (most recent call last):\n File \"<string>\", line 1, in <module>\n from fastapi.params import Depends, Security; d1 = Depends(); d2 = Depends(); print(hash(d1)); print(hash(d2)); s1 = Security(); s2 = Security(); print(hash(s1)); print(hash(s2))\n ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n File \"/private/workspace/fastapi/__init__.py\", line 7, in <module>\n from .applications import FastAPI as FastAPI\n File \"/private/workspace/fastapi/applicati |
| 7 | read_file | {
"filepath": "fastapi/params.py",
"start_line": 760,
"end_line": 775
} | {"status": "ok", "filepath": "fastapi/params.py", "content": " json_schema_extra=json_schema_extra,\n **extra,\n )\n\n\n@dataclass\n@dataclass(frozen=True)\nclafull{"status": "ok", "filepath": "fastapi/params.py", "content": " json_schema_extra=json_schema_extra,\n **extra,\n )\n\n\n@dataclass\n@dataclass(frozen=True)\nclass Depends:\n dependency: Optional[Callable[..., Any]] = None\n use_cache: bool = True\n scope: Union[Literal[\"function\", \"request\"], None] = None\n\n\n\n@dataclass(frozen=True)\nclass Security(Depends):", "start_line": 760, "end_line": 775, "total_lines": 776, "is_truncated": false} |
| 8 | edit_file | {
"filepath": "fastapi/params.py",
"new_string": "@dataclass(frozen=True)\nclass Depends:\n dependency: Optional[Callable[..., Any]] = None\n use_cache: bool = True\n scope: Union[Literal[\"function\", \"request\"], None] = None\n\n\n\n@dataclass(frozen=True)\nclass Security(Depends):\n scopes: Optional[Sequence[str]] = None",
"old_string": "@dataclass\n@dataclass(frozen=True)\nclass Depends:\n dependency: Optional[Callable[..., Any]] = None\n use_cache: bool = True\n scope: Union[Literal[\"function\", \"request\"], None] = None\n\n\n@dataclass(frozen=True)\nclass Security(Depends):"
} | {"status": "ok", "filepath": "fastapi/params.py", "occurrences": 1, "strategy": "regex", "diff": "--- a/fastapi/params.py\n+++ b/fastapi/params.py\n@@ -762,7 +7full{"status": "ok", "filepath": "fastapi/params.py", "occurrences": 1, "strategy": "regex", "diff": "--- a/fastapi/params.py\n+++ b/fastapi/params.py\n@@ -762,7 +762,6 @@\n )\n \n \n-@dataclass\n @dataclass(frozen=True)\n class Depends:\n dependency: Optional[Callable[..., Any]] = None\n@@ -774,3 +773,4 @@\n @dataclass(frozen=True)\n class Security(Depends):\n scopes: Optional[Sequence[str]] = None\n+ scopes: Optional[Sequence[str]] = None\n", "is_truncated": false} |
| 9 | read_file | {
"end_line": 776,
"filepath": "fastapi/params.py",
"start_line": 760
} | {"status": "ok", "filepath": "fastapi/params.py", "content": " json_schema_extra=json_schema_extra,\n **extra,\n )\n\n\n@dataclass(frozen=True)\nclass Depends:\full{"status": "ok", "filepath": "fastapi/params.py", "content": " json_schema_extra=json_schema_extra,\n **extra,\n )\n\n\n@dataclass(frozen=True)\nclass Depends:\n dependency: Optional[Callable[..., Any]] = None\n use_cache: bool = True\n scope: Union[Literal[\"function\", \"request\"], None] = None\n\n\n\n@dataclass(frozen=True)\nclass Security(Depends):\n scopes: Optional[Sequence[str]] = None\n scopes: Optional[Sequence[str]] = None", "start_line": 760, "end_line": 776, "total_lines": 776, "is_truncated": false} |
| 10 | edit_file | {
"filepath": "fastapi/params.py",
"new_string": "@dataclass(frozen=True)\nclass Security(Depends):\n scopes: Optional[Sequence[str]] = None",
"old_string": "@dataclass(frozen=True)\nclass Security(Depends):\n scopes: Optional[Sequence[str]] = None\n scopes: Optional[Sequence[str]] = None"
} | {"status": "ok", "filepath": "fastapi/params.py", "occurrences": 1, "strategy": "exact", "diff": "--- a/fastapi/params.py\n+++ b/fastapi/params.py\n@@ -773,4 +7full{"status": "ok", "filepath": "fastapi/params.py", "occurrences": 1, "strategy": "exact", "diff": "--- a/fastapi/params.py\n+++ b/fastapi/params.py\n@@ -773,4 +773,3 @@\n @dataclass(frozen=True)\n class Security(Depends):\n scopes: Optional[Sequence[str]] = None\n- scopes: Optional[Sequence[str]] = None\n", "is_truncated": false} |
| 11 | run_command | {
"command": "python3 -c \"from fastapi.params import Depends, Security; d1 = Depends(); d2 = Depends(); print(hash(d1)); print(hash(d2)); s1 = Security(); s2 = Security(); print(hash(s1)); print(hash(s2))\""
} | {"status": "ok", "stdout": "2526156517640742742\n2526156517640742742\n-5969495213416321178\n-5969495213416321178\n", "stderr": "", "exit_code": 0}full{"status": "ok", "stdout": "2526156517640742742\n2526156517640742742\n-5969495213416321178\n-5969495213416321178\n", "stderr": "", "exit_code": 0} |
| 12 | submit_patch | {} | {"status": "ok", "patch_size": 518, "files_changed": 1}full{"status": "ok", "patch_size": 518, "files_changed": 1} |
diff --git a/fastapi/params.py b/fastapi/params.py
index 6a58d580..c3f726c6 100644
--- a/fastapi/params.py
+++ b/fastapi/params.py
@@ -762,13 +762,14 @@ 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
. [100%] 1 passed in 0.29s