Browse Source

Merge 4bddd72850 into 6e69d62bfe

pull/9425/merge
Robert Hofer 1 day ago
committed by GitHub
parent
commit
66965fbe12
No known key found for this signature in database GPG Key ID: B5690EEEBB952194
  1. 2
      fastapi/dependencies/utils.py
  2. 27
      tests/test_return_none_future_annotations.py

2
fastapi/dependencies/utils.py

@ -255,7 +255,7 @@ def get_typed_return_annotation(call: Callable[..., Any]) -> Any:
signature = inspect.signature(call)
annotation = signature.return_annotation
if annotation is inspect.Signature.empty:
if annotation == "None" or annotation is inspect.Signature.empty:
return None
globalns = getattr(call, "__globals__", {})

27
tests/test_return_none_future_annotations.py

@ -0,0 +1,27 @@
from __future__ import annotations
import http
import logging
from fastapi import APIRouter, FastAPI
from fastapi.testclient import TestClient
router = APIRouter()
app = FastAPI()
@router.get("/no-content", status_code=http.HTTPStatus.NO_CONTENT)
def return_no_content() -> None:
logging.info("endpoint called")
app.include_router(router)
client = TestClient(app)
def test_no_content():
response = client.get("/no-content")
assert response.status_code == http.HTTPStatus.NO_CONTENT, response.text
assert not response.content
Loading…
Cancel
Save