Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added boolean dunder methods #4124

Merged
merged 3 commits into from
Oct 2, 2019
Merged
Show file tree
Hide file tree
Changes from 2 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/4102.misc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
web.Application object now has a boolean value of True
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

web.BaseRequest is also affected, isn't it?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oops 😄

3 changes: 3 additions & 0 deletions aiohttp/web_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -338,6 +338,9 @@ def __call__(self) -> 'Application':
def __repr__(self) -> str:
return "<Application 0x{:x}>".format(id(self))

def __bool__(self) -> bool:
return True


class CleanupError(RuntimeError):
@property
Expand Down
3 changes: 3 additions & 0 deletions aiohttp/web_request.py
Original file line number Diff line number Diff line change
Expand Up @@ -682,6 +682,9 @@ def __repr__(self) -> str:
def __eq__(self, other: object) -> bool:
return id(self) == id(other)

def __bool__(self) -> bool:
return True

async def _prepare_hook(self, response: StreamResponse) -> None:
return

Expand Down
5 changes: 5 additions & 0 deletions tests/test_web_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -457,3 +457,8 @@ def test_forbid_changing_frozen_app() -> None:
app.freeze()
with pytest.raises(RuntimeError):
app['key'] = 'value'


def test_app_boolean() -> None:
app = web.Application()
assert app
2 changes: 2 additions & 0 deletions tests/test_web_request.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ def test_base_ctor() -> None:

assert '__dict__' not in dir(req)

assert req


def test_ctor() -> None:
req = make_mocked_request('GET', '/path/to?a=1&b=2')
Expand Down