resolved RESOLVED PASS · 14 tool calls · 74 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\" ."
} | {"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 | run_command | {
"command": "grep -rn \"class Security\" ."
} | {"status": "ok", "stdout": "./fastapi/params.py:773:class Security(Depends):\n./fastapi/security/oauth2.py:614:class SecurityScopes:\n./fastapi/security/base.pyfull{"status": "ok", "stdout": "./fastapi/params.py:773:class Security(Depends):\n./fastapi/security/oauth2.py:614:class SecurityScopes:\n./fastapi/security/base.py:4:class SecurityBase:\n./fastapi/dependencies/models.py:19:class SecurityRequirement:\n./fastapi/openapi/models.py:337:class SecuritySchemeType(Enum):\n./fastapi/openapi/models.py:344:class SecurityBase(BaseModelWithConfig):\n", "stderr": "", "exit_code": 0} |
| 3 | run_command | {
"command": "sed -n '760,780p' fastapi/params.py"
} | {"status": "ok", "stdout": " json_schema_extra=json_schema_extra,\n **extra,\n )\n\n\n@dataclass\nclass Depends:\n dependency: Optional[Callable[..., Any]] = Nofull{"status": "ok", "stdout": " json_schema_extra=json_schema_extra,\n **extra,\n )\n\n\n@dataclass\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\nclass Security(Depends):\n scopes: Optional[Sequence[str]] = None\n", "stderr": "", "exit_code": 0} |
| 4 | run_command | {
"command": "python3 - <<'PY'\nfrom fastapi.params import Depends, Security\nfrom typing import Callable\n\ndef mock_dep():\n pass\n\nd1 = Depends(mock_dep)\nd2 = Depends(mock_dep)\ns1 = Security(mock_dep)\ns2 = Security(mock_dep)\n\nprint(f\"Depends hashable: {hash(d1) == hash(d2)}\")\ntry:\n print(f\"Depends in set: {len({d1, d2})}\")\nexcept Exception as e:\n print(f\"Depends in set error: {e}\")\n\nprint(f\"Security hashable: {hash(s1) == hash(s2)}\")\ntry:\n print(f\"Security in set: {len({s1, s2})}\")\nexcept Exception as e:\n print(f\"Security in set error: {e}\")\nPY\n"
} | {"status": "error", "error_type": "CommandError", "error_message": "Traceback (most recent call last):\n File \"<stdin>\", line 12, in <module>\nTypeError: unhafull{"status": "error", "error_type": "CommandError", "error_message": "Traceback (most recent call last):\n File \"<stdin>\", line 12, in <module>\nTypeError: unhashable type: 'Depends'\n", "details": {"stdout": "", "stderr": "Traceback (most recent call last):\n File \"<stdin>\", line 12, in <module>\nTypeError: unhashable type: 'Depends'\n", "exit_code": 1}} |
| 5 | run_command | {
"command": "cd /workspace && python3 - <<'PY'\nfrom pathlib import Path\np = Path(\"fastapi/params.py\")\ns = p.read_text()\nold = \"\"\"@dataclass\nclass Depends:\n dependency: Optional[Callable[..., Any]] = None\n use_cache: bool = True\n scope: Union[Literal[\"function\", \"request\"], None] = None\"\"\"\nnew = \"\"\"@dataclass(frozen=True)\nclass Depends:\n dependency: Optional[Callable[..., Any]] = None\n use_cache: bool = True\n scope: Union[Literal[\"function\", \"request\"], None] = None\"\"\"\nassert s.count(old) == 1, (\"old text found this many times:\", s.count(old))\nt = s.replace(old, new)\np.write_text(t)\nPY\n"
} | {"status": "ok", "stdout": "", "stderr": "", "exit_code": 0}full{"status": "ok", "stdout": "", "stderr": "", "exit_code": 0} |
| 6 | run_command | {
"command": "python3 -m py_compile fastapi/params.py"
} | {"status": "ok", "stdout": "", "stderr": "", "exit_code": 0}full{"status": "ok", "stdout": "", "stderr": "", "exit_code": 0} |
| 7 | run_command | {
"command": "python3 - <<'PY'\nfrom fastapi.params import Depends, Security\nfrom typing import Callable\n\ndef mock_dep():\n pass\n\nd1 = Depends(mock_dep)\nd2 = Depends(mock_dep)\ns1 = Security(mock_dep)\ns2 = Security(mock_dep)\n\nprint(f\"Depends hashable: {hash(d1) == hash(d2)}\")\ntry:\n print(f\"Depends in set: {len({d1, d2})}\")\nexcept Exception as e:\n print(f\"Depends in set error: {e}\")\n\nprint(f\"Security hashable: {hash(s1) == hash(s2)}\")\ntry:\n print(f\"Security in set: {len({s1, s2})}\")\nexcept Exception as e:\n print(f\"Security in set error: {e}\")\nPY\n"
} | {"status": "error", "error_type": "CommandError", "error_message": "Traceback (most recent call last):\n File \"<stdin>\", line 1, in <module>\n File \"/privatefull{"status": "error", "error_type": "CommandError", "error_message": "Traceback (most recent call last):\n File \"<stdin>\", line 1, in <module>\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 772, in <module>\n @dataclass\n ^^^^^^^^^\n File \"/Users/jp/.local/share/uv/python/cpython-3.13.15-macos-aarch64-none/lib/python3.13/dataclasses.py\", line 1354, in dataclass\n return wrap(cls)\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 1038, in _process_class\n raise TypeError('cannot inherit non-frozen dataclass from a '\n 'frozen one')\nTypeError: cannot inherit non-frozen dataclass from a frozen one\n", "details": {"stdout": "", "stderr": "Traceback (most recent call last):\n File \"<stdin>\", line 1, in <module>\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 772, in <module>\n @dataclass\n ^^^^^^^^^\n File \"/Users/jp/.local/share/uv/python |
| 8 | run_command | {
"command": "cd /workspace && python3 - <<'PY'\nfrom pathlib import Path\np = Path(\"fastapi/params.py\")\ns = p.read_text()\nold = \"\"\"@dataclass\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\nclass Security(Depends):\n scopes: Optional[Sequence[str]] = None\"\"\"\nnew = \"\"\"@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):\n scopes: Optional[Sequence[str]] = None\"\"\"\nassert s.count(old) == 1, (\"old text found this many times:\", s.count(old))\nt = s.replace(old, new)\np.write_text(t)\nPY\n"
} | {"status": "error", "error_type": "CommandError", "error_message": "Traceback (most recent call last):\n File \"<stdin>\", line 24, in <module>\nAssertionError:full{"status": "error", "error_type": "CommandError", "error_message": "Traceback (most recent call last):\n File \"<stdin>\", line 24, in <module>\nAssertionError: ('old text found this many times:', 0)\n", "details": {"stdout": "", "stderr": "Traceback (most recent call last):\n File \"<stdin>\", line 24, in <module>\nAssertionError: ('old text found this many times:', 0)\n", "exit_code": 1}} |
| 9 | run_command | {
"command": "sed -n '765,778p' fastapi/params.py"
} | {"status": "ok", "stdout": "@dataclass(frozen=True)\nclass Depends:\n dependency: Optional[Callable[..., Any]] = None\n use_cache: bool = True\n scope: Union[Lifull{"status": "ok", "stdout": "@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\nclass Security(Depends):\n scopes: Optional[Sequence[str]] = None\n", "stderr": "", "exit_code": 0} |
| 10 | run_command | {
"command": "cd /workspace && python3 - <<'PY'\nfrom pathlib import Path\np = Path(\"fastapi/params.py\")\ns = p.read_text()\nold = \"\"\"@dataclass\nclass Security(Depends):\n scopes: Optional[Sequence[str]] = None\"\"\"\nnew = \"\"\"@dataclass(frozen=True)\nclass Security(Depends):\n scopes: Optional[Sequence[str]] = None\"\"\"\nassert s.count(old) == 1, (\"old text found this many times:\", s.count(old))\nt = s.replace(old, new)\np.write_text(t)\nPY\n"
} | {"status": "ok", "stdout": "", "stderr": "", "exit_code": 0}full{"status": "ok", "stdout": "", "stderr": "", "exit_code": 0} |
| 11 | run_command | {
"command": "python3 -m py_compile fastapi/params.py"
} | {"status": "ok", "stdout": "", "stderr": "", "exit_code": 0}full{"status": "ok", "stdout": "", "stderr": "", "exit_code": 0} |
| 12 | run_command | {
"command": "python3 - <<'PY'\nfrom fastapi.params import Depends, Security\nfrom typing import Callable\n\ndef mock_dep():\n pass\n\nd1 = Depends(mock_dep)\nd2 = Depends(mock_dep)\ns1 = Security(mock_dep)\ns2 = Security(mock_dep)\n\nprint(f\"Depends hashable: {hash(d1) == hash(d2)}\")\ntry:\n print(f\"Depends in set: {len({d1, d2})}\")\nexcept Exception as e:\n print(f\"Depends in set error: {e}\")\n\nprint(f\"Security hashable: {hash(s1) == hash(s2)}\")\ntry:\n print(f\"Security in set: {len({s1, s2})}\")\nexcept Exception as e:\n print(f\"Security in set error: {e}\")\nPY\n"
} | {"status": "ok", "stdout": "Depends hashable: True\nDepends in set: 1\nSecurity hashable: True\nSecurity in set: 1\n", "stderr": "", "exit_code": 0}full{"status": "ok", "stdout": "Depends hashable: True\nDepends in set: 1\nSecurity hashable: True\nSecurity in set: 1\n", "stderr": "", "exit_code": 0} |
| 13 | run_command | {
"command": "git diff"
} | {"status": "ok", "stdout": "diff --git a/fastapi/params.py b/fastapi/params.py\nindex 6a58d580..6d07df35 100644\n--- a/fastapi/params.py\n+++ b/fastapi/params.pfull{"status": "ok", "stdout": "diff --git a/fastapi/params.py b/fastapi/params.py\nindex 6a58d580..6d07df35 100644\n--- a/fastapi/params.py\n+++ b/fastapi/params.py\n@@ -762,13 +762,13 @@ class File(Form): # type: ignore[misc]\n )\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+@dataclass(frozen=True)\n class Security(Depends):\n scopes: Optional[Sequence[str]] = None\n", "stderr": "", "exit_code": 0} |
| 14 | run_command | {
"command": "submit_patch"
} | {"status": "error", "error_type": "CommandError", "error_message": "/bin/bash: submit_patch: command not found\n", "details": {"stdout": "", "stderr": "/bin/basfull{"status": "error", "error_type": "CommandError", "error_message": "/bin/bash: submit_patch: command not found\n", "details": {"stdout": "", "stderr": "/bin/bash: submit_patch: command not found\n", "exit_code": 127}} |
| 15 | submit_patch | {} | {"status": "ok", "patch_size": 516, "files_changed": 1}full{"status": "ok", "patch_size": 516, "files_changed": 1} |
diff --git a/fastapi/params.py b/fastapi/params.py
index 6a58d580..6d07df35 100644
--- a/fastapi/params.py
+++ b/fastapi/params.py
@@ -762,13 +762,13 @@ 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