Skip to content

Preserve explicit -> None return annotations in @depends-wrapped endpoint signatures#17

Merged
Minibrams merged 3 commits intomainfrom
copilot/fix-depends-modifies-return-type
Mar 30, 2026
Merged

Preserve explicit -> None return annotations in @depends-wrapped endpoint signatures#17
Minibrams merged 3 commits intomainfrom
copilot/fix-depends-modifies-return-type

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Mar 29, 2026

@depends was rebuilding wrapped function signatures with a type-hint-resolved return annotation, which converted explicit -> None into NoneType. In FastAPI, this could cause incorrect response model inference and trigger 204 No Content assertion errors unless users added manual workarounds (response_model=None or removing return typing).

  • Signature reconstruction fix

    • Updated depends() to keep the original function’s return annotation verbatim when creating __signature__.
    • This preserves None exactly as authored and avoids changing FastAPI route semantics for no-content endpoints.
  • Regression coverage

    • Added a focused test for an endpoint declared as async def ... -> None with status_code=204 and a @depends decorator.
    • The test verifies the route is valid and returns an empty 204 response without requiring workaround configuration.
# before (could become NoneType through hint resolution)
new_signature = original_signature.replace(
    parameters=tuple(all_params.values()),
    return_annotation=hints.get("return", original_signature.return_annotation),
)

# after (preserve authored return annotation)
new_signature = original_signature.replace(
    parameters=tuple(all_params.values()),
    return_annotation=original_signature.return_annotation,
)

✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Copilot AI changed the title [WIP] Fix @depends modifying function return type when it's None Preserve explicit -> None return annotations in @depends-wrapped endpoint signatures Mar 29, 2026
Copilot AI requested a review from Minibrams March 29, 2026 13:32
@FieryRMS
Copy link
Copy Markdown

I'll get put out of my job cuz of copilot 🫡
but PR LGTM

ps: i dont have a job

@Minibrams Minibrams marked this pull request as ready for review March 30, 2026 07:29
@Minibrams Minibrams merged commit c0ed08f into main Mar 30, 2026
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

@depends modifies function return type when it's None

3 participants