diff --git a/fastapi_decorators/decorators.py b/fastapi_decorators/decorators.py index 62c5663..329ca51 100644 --- a/fastapi_decorators/decorators.py +++ b/fastapi_decorators/decorators.py @@ -82,7 +82,7 @@ def decorator(func: F) -> F: new_signature = original_signature.replace( parameters=tuple(all_params.values()), - return_annotation=hints.get("return", original_signature.return_annotation), + return_annotation=original_signature.return_annotation, ) wrapper = _create_wrapper(func, all_params) diff --git a/tests/test_app.py b/tests/test_app.py index d8a774d..eae5a10 100644 --- a/tests/test_app.py +++ b/tests/test_app.py @@ -1,7 +1,9 @@ from time import sleep, time +from fastapi import FastAPI, status from fastapi.testclient import TestClient import pytest from tests.app import app, fake_db, rate_limit_store, cache_storage, error_log +from fastapi_decorators import depends client = TestClient(app) @@ -168,3 +170,22 @@ def test_expects_header() -> None: response = client.get("/headers", headers=headers) assert response.status_code == 200 assert response.json() == headers + + +def test_depends_keeps_none_return_annotation_for_204() -> None: + test_app = FastAPI() + + @depends + def with_test() -> None: + pass + + @test_app.get("/test", status_code=status.HTTP_204_NO_CONTENT) + @with_test + async def endpoint() -> None: + pass + + assert endpoint is not None + test_client = TestClient(test_app) + response = test_client.get("/test") + assert response.status_code == status.HTTP_204_NO_CONTENT + assert response.content == b""