Repository: aio-libs/aiohttp

Issue:
Disable body parameter in HTTPException constructor
Now the exception can be created with either `body` or `text`.
It over complicates things in a light of removing inheritance from `web.Response`.

Let's deprecate `body` before changing the inheritance hierarchy.
Disable body parameter in HTTPException constructor
Now the exception can be created with either `body` or `text`.
It over complicates things in a light of removing inheritance from `web.Response`.

Let's deprecate `body` before changing the inheritance hierarchy.


Discussion:
[GitMate.io](https://gitmate.io) thinks possibly related issues are https://github.com/aio-libs/aiohttp/issues/593 (Add charset parameter to web.Response constructor), https://github.com/aio-libs/aiohttp/issues/1992 ([enhancement] Add ability to disable automatic decompression of body), https://github.com/aio-libs/aiohttp/issues/193 (Should aiohttp.web.Response accept body as positional parameter?), https://github.com/aio-libs/aiohttp/issues/2067 (Disable Cookie Handling), and https://github.com/aio-libs/aiohttp/issues/2262 (Disable DNS cache).
[GitMate.io](https://gitmate.io) thinks possibly related issues are https://github.com/aio-libs/aiohttp/issues/593 (Add charset parameter to web.Response constructor), https://github.com/aio-libs/aiohttp/issues/1992 ([enhancement] Add ability to disable automatic decompression of body), https://github.com/aio-libs/aiohttp/issues/193 (Should aiohttp.web.Response accept body as positional parameter?), https://github.com/aio-libs/aiohttp/issues/2067 (Disable Cookie Handling), and https://github.com/aio-libs/aiohttp/issues/2262 (Disable DNS cache).

Resolving patch:
diff --git a/aiohttp/web_exceptions.py b/aiohttp/web_exceptions.py
--- a/aiohttp/web_exceptions.py
+++ b/aiohttp/web_exceptions.py
@@ -1,3 +1,4 @@
+import warnings
 from typing import Any, Dict, Iterable, List, Optional, Set  # noqa
 
 from .typedefs import LooseHeaders, StrOrURL
@@ -85,6 +86,10 @@ def __init__(self, *,
                  body: Any=None,
                  text: Optional[str]=None,
                  content_type: Optional[str]=None) -> None:
+        if body is not None:
+            warnings.warn(
+                "body argument is deprecated for http web exceptions",
+                DeprecationWarning)
         Response.__init__(self, status=self.status_code,
                           headers=headers, reason=reason,
                           body=body, text=text, content_type=content_type)


Test patch:
diff --git a/tests/test_web_exceptions.py b/tests/test_web_exceptions.py
--- a/tests/test_web_exceptions.py
+++ b/tests/test_web_exceptions.py
@@ -139,8 +139,9 @@ def test_override_body_with_text() -> None:
 
 def test_override_body_with_binary() -> None:
     txt = "<html><body>Page not found</body></html>"
-    resp = web.HTTPNotFound(body=txt.encode('utf-8'),
-                            content_type="text/html")
+    with pytest.warns(DeprecationWarning):
+        resp = web.HTTPNotFound(body=txt.encode('utf-8'),
+                                content_type="text/html")
     assert 404 == resp.status
     assert txt.encode('utf-8') == resp.body
     assert txt == resp.text