Repository: litestar-org/litestar

Issue:
Fix: remove  `NoReturn` as a supported return value for `delete`.
### Discussed in https://github.com/starlite-api/starlite/discussions/583

<div type='discussions-op-text'>

<sup>Originally posted by **Goldziher** October 13, 2022</sup>
We currenty support `NoReturn` as a valid return value for the `delete` method, which cannot support returning a value with uvicorn (which freaks out if it does return a value, while hypercorn and other servers do not). 

We should decide how we want to proceed given that in the official PEP for this type it is determined that it should be used only for special functions that never return a value, like endless loops or functions that raise exceptions: https://peps.python.org/pep-0484/#the-noreturn-type. </div>


Discussion:

Resolving patch:
diff --git a/starlite/handlers/http.py b/starlite/handlers/http.py
--- a/starlite/handlers/http.py
+++ b/starlite/handlers/http.py
@@ -7,7 +7,6 @@
     Callable,
     Dict,
     List,
-    NoReturn,
     Optional,
     Type,
     Union,
@@ -574,11 +573,11 @@ def _validate_handler_function(self) -> None:
         if return_annotation is Signature.empty:
             raise ImproperlyConfiguredException(
                 "A return value of a route handler function should be type annotated."
-                "If your function doesn't return a value or returns None, annotate it as returning 'NoReturn' or 'None' respectively."
+                "If your function doesn't return a value, annotate it as returning 'None'."
             )
         if (
             self.status_code < 200 or self.status_code in {HTTP_204_NO_CONTENT, HTTP_304_NOT_MODIFIED}
-        ) and return_annotation not in {NoReturn, None}:
+        ) and return_annotation is not None:
             raise ImproperlyConfiguredException(
                 "A status code 204, 304 or in the range below 200 does not support a response body."
                 "If the function should return a value, change the route handler status code to an appropriate value.",
diff --git a/starlite/response.py b/starlite/response.py
--- a/starlite/response.py
+++ b/starlite/response.py
@@ -1,14 +1,4 @@
-from typing import (
-    TYPE_CHECKING,
-    Any,
-    Dict,
-    Generic,
-    NoReturn,
-    Optional,
-    TypeVar,
-    Union,
-    cast,
-)
+from typing import TYPE_CHECKING, Any, Dict, Generic, Optional, TypeVar, Union, cast
 
 import yaml
 from orjson import OPT_INDENT_2, OPT_OMIT_MICROSECONDS, OPT_SERIALIZE_NUMPY, dumps
@@ -83,10 +73,8 @@ def render(self, content: Any) -> bytes:
             An encoded bytes string
         """
         try:
-            if (
-                content is None
-                or content is NoReturn
-                and (self.status_code < 100 or self.status_code in {HTTP_204_NO_CONTENT, HTTP_304_NOT_MODIFIED})
+            if content is None and (
+                self.status_code < 100 or self.status_code in {HTTP_204_NO_CONTENT, HTTP_304_NOT_MODIFIED}
             ):
                 return b""
             if self.media_type == MediaType.JSON:


Test patch:
diff --git a/tests/handlers/http/test_delete.py b/tests/handlers/http/test_delete.py
--- a/tests/handlers/http/test_delete.py
+++ b/tests/handlers/http/test_delete.py
@@ -1,15 +1,10 @@
-from typing import Any, NoReturn
-
-import pytest
-
 from starlite import delete
 from starlite.testing import create_test_client
 
 
-@pytest.mark.parametrize("return_annotation", (None, NoReturn))
-def test_handler_return_none_and_204_status_response_empty(return_annotation: Any) -> None:
+def test_handler_return_none_and_204_status_response_empty() -> None:
     @delete(path="/")
-    async def route() -> return_annotation:  # type: ignore[valid-type]
+    async def route() -> None:
         return None
 
     with create_test_client(route_handlers=[route]) as client: