Skip to content

Response is "falsy" #10119

@Derkades

Description

@Derkades

Describe the bug

bool(web.Response()) evaluates to False. I suspect this is because Response inherits from MutableMapping.

This may cause confusion when checking for if response: instead of if response is not None.

To Reproduce

>>> response = web.Response()
>>> bool(response)
False
>>> response["a"] = 1
>>> bool(response)
True

Expected behavior

I personally think Response should always be "truthy".

Logs/tracebacks

N/A

Python Version

3.13.0

aiohttp Version

3.11.9

multidict Version

6.1.0

propcache Version

0.2.0

yarl Version

1.17.1

OS

Fedora 41

Related component

Server, Client

Additional context

No response

Code of Conduct

  • I agree to follow the aio-libs Code of Conduct

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions