Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGES/10119.bugfix.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Response is now always True, instead of using MutableMapping behaviour (False when map is empty)
3 changes: 3 additions & 0 deletions aiohttp/web_response.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):

Expand Down
1 change: 1 addition & 0 deletions tests/test_web_request.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"]

Expand Down
1 change: 1 addition & 0 deletions tests/test_web_response.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"]

Expand Down
Loading