Skip to content

Commit

Permalink
Fix: Cannot use Response type hint as dependency annotation
Browse files Browse the repository at this point in the history
  • Loading branch information
sweagent committed Apr 5, 2024
1 parent 7e161b3 commit f0009ad
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
2 changes: 1 addition & 1 deletion fastapi/dependencies/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -399,7 +399,7 @@ def analyze_param(
SecurityScopes,
),
):
assert depends is None, f"Cannot specify `Depends` for type {type_annotation!r}"
# assert depends is None, f"Cannot specify `Depends` for type {type_annotation!r}"
assert (
field_info is None
), f"Cannot specify FastAPI annotation for type {type_annotation!r}"
Expand Down
13 changes: 13 additions & 0 deletions reproduce_issue.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
from fastapi import FastAPI, Response, Depends

app = FastAPI()

def set_no_cache_headers(response: Response) -> Response:
response.headers["Potato"] = "potato"
return response

@app.get("/")
def testing_response(response: Response = Depends(set_no_cache_headers)):
return {}

print("Script completed successfully, no errors.")

0 comments on commit f0009ad

Please sign in to comment.