diff --git a/CHANGES/10119.bugfix.rst b/CHANGES/10119.bugfix.rst new file mode 100644 index 00000000000..86d2511f5b5 --- /dev/null +++ b/CHANGES/10119.bugfix.rst @@ -0,0 +1 @@ +Response is now always True, instead of using MutableMapping behaviour (False when map is empty) diff --git a/aiohttp/web_response.py b/aiohttp/web_response.py index 2feffba9e68..88a1d145da0 100644 --- a/aiohttp/web_response.py +++ b/aiohttp/web_response.py @@ -504,6 +504,9 @@ def __hash__(self) -> int: def __eq__(self, other: object) -> bool: return self is other + def __bool__(self) -> bool: + return True + class Response(StreamResponse): diff --git a/tests/test_web_request.py b/tests/test_web_request.py index 0086d9b1688..932e3efd02d 100644 --- a/tests/test_web_request.py +++ b/tests/test_web_request.py @@ -287,6 +287,7 @@ def test_match_info() -> None: def test_request_is_mutable_mapping() -> None: req = make_mocked_request("GET", "/") assert isinstance(req, MutableMapping) + assert req # even when the MutableMapping is empty, request should always be True req["key"] = "value" assert "value" == req["key"] diff --git a/tests/test_web_response.py b/tests/test_web_response.py index dff883d4570..f8cf233e148 100644 --- a/tests/test_web_response.py +++ b/tests/test_web_response.py @@ -93,6 +93,7 @@ def test_stream_response_eq() -> None: def test_stream_response_is_mutable_mapping() -> None: resp = web.StreamResponse() assert isinstance(resp, collections.abc.MutableMapping) + assert resp # even when the MutableMapping is empty, response should always be True resp["key"] = "value" assert "value" == resp["key"]