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

run_app: make print=None disable printing #2260

Merged
merged 2 commits into from
Sep 12, 2017
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 CONTRIBUTORS.txt
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ Andrew Leech
Andrew Lytvyn
Andrew Svetlov
Andrii Soldatenko
Antoine Pietri
Anton Kasyanov
Arthur Darcet
Ben Bader
Expand Down
5 changes: 3 additions & 2 deletions aiohttp/web.py
Original file line number Diff line number Diff line change
Expand Up @@ -447,8 +447,9 @@ def run_app(app, *, host=None, port=None, path=None, sock=None,
pass

try:
print("======== Running on {} ========\n"
"(Press CTRL+C to quit)".format(', '.join(uris)))
if print:
Copy link

Choose a reason for hiding this comment

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

if callable(print): maybe? The discoverability of this argument is poor, intuition makes me want to use print=True which will fail miserably.

Copy link
Member

Choose a reason for hiding this comment

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

better to "fail miserably" than fail silently. In neither case would print=True do what you expected.

Much better to use python typing hinting for public methods like this once 3.4 support is dropped.

print("======== Running on {} ========\n"
"(Press CTRL+C to quit)".format(', '.join(uris)))
loop.run_forever()
except (GracefulExit, KeyboardInterrupt): # pragma: no cover
pass
Expand Down
1 change: 1 addition & 0 deletions changes/2260.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
run_app: Make print=None disable printing
3 changes: 2 additions & 1 deletion docs/web_reference.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2400,7 +2400,8 @@ Utilities
``None`` for HTTP connection.

:param print: a callable compatible with :func:`print`. May be used
to override STDOUT output or suppress it.
to override STDOUT output or suppress it. Passing `None`
disables output.

:param int backlog: the number of unaccepted connections that the
system will allow before refusing new
Expand Down
2 changes: 1 addition & 1 deletion tests/test_run_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ def test_run_app_mixed_bindings(mocker, run_app_kwargs, expected_server_calls,
loop = mocker.MagicMock()
mocker.patch('asyncio.gather')

web.run_app(app, loop=loop, print=lambda *args: None, **run_app_kwargs)
web.run_app(app, loop=loop, print=None, **run_app_kwargs)

assert loop.create_unix_server.mock_calls == expected_unix_server_calls
assert loop.create_server.mock_calls == expected_server_calls
Expand Down