Skip to content

Commit

Permalink
added boolean dunder methods (#4124)
Browse files Browse the repository at this point in the history
  • Loading branch information
deltaclock authored and asvetlov committed Oct 2, 2019
1 parent cfb40b7 commit a1a1a53
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGES/4102.misc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
web.Application and web.BaseRequest objects now has a boolean value of True
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 @@ -450,3 +450,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

0 comments on commit a1a1a53

Please sign in to comment.