Skip to content

Commit

Permalink
Ensure Response is True even when map is empty (#10172)
Browse files Browse the repository at this point in the history
Fixes #10119

Technically a breaking change, but I can't imagine anyone depending on
this.
  • Loading branch information
Derkades authored Dec 18, 2024
1 parent 7b5d54a commit e45c3b8
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 0 deletions.
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

0 comments on commit e45c3b8

Please sign in to comment.