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

Conversation

seirl
Copy link
Contributor

@seirl seirl commented Sep 11, 2017

run_app currently takes a callable compatible with print(). If you want to disable output completely (which happens all the time when you're writing test suites or similar), you have to call run_app with print=lambda *_, **__: None, which is not very pretty and confusing.

This behavior is annoying, so this change makes print=None a special case that disables output completely.

This change is backwards-compatible.

@samuelcolvin
Copy link
Member

+1: for this, but I've always thought the print argument was ugly.

Really this should be logged, but since python (very unfortunately) python doesn't have a NOTICE log level I'm not sure of the proper solution.

Perhaps aiohttp should have a log which is setup to write to stdout out at INFO level by default?

(I'm guess you had to create the PR before you could add a file to changes?)

@seirl seirl force-pushed the master branch 2 times, most recently from 15cfdb6 to e96ed58 Compare September 11, 2017 11:03
@seirl
Copy link
Contributor Author

seirl commented Sep 11, 2017 via email

@seirl
Copy link
Contributor Author

seirl commented Sep 11, 2017

The lambda assignment made QA explode so I'm doing a regular def instead...

@asvetlov
Copy link
Member

I'm ok with PR but disagree with logging usage for printing text like Press Ctrl+C to quit.

aiohttp/web.py Outdated
@@ -422,6 +422,10 @@ def run_app(app, *, host=None, port=None, path=None, sock=None,
app._set_loop(loop)
loop.run_until_complete(app.startup())

if print is None:
Copy link
Member

Choose a reason for hiding this comment

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

much easier just do if print below before calling 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.

I guess, if that's the only place you ever plan to use that print argument?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

There, I updated it.

Copy link
Member

Choose a reason for hiding this comment

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

looks like you having a linting error 😄

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Woops, failed my block selection. There you go, sorry :-P

@seirl seirl force-pushed the master branch 2 times, most recently from d5dfb62 to 7b20128 Compare September 11, 2017 11:35
@codecov-io
Copy link

codecov-io commented Sep 11, 2017

Codecov Report

Merging #2260 into master will increase coverage by <.01%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #2260      +/-   ##
==========================================
+ Coverage   97.31%   97.31%   +<.01%     
==========================================
  Files          39       39              
  Lines        7944     7945       +1     
  Branches     1377     1378       +1     
==========================================
+ Hits         7731     7732       +1     
  Misses         90       90              
  Partials      123      123
Impacted Files Coverage Δ
aiohttp/web.py 99.66% <100%> (ø) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update c6c04f2...85dda55. Read the comment docs.

@seirl
Copy link
Contributor Author

seirl commented Sep 11, 2017

... wtf?

@samuelcolvin
Copy link
Member

codecov occasionally goes mad and does strange things. Is the branch bases off current master?

@seirl
Copy link
Contributor Author

seirl commented Sep 11, 2017

Sure, parent commit is c7e8356 .

@samuelcolvin
Copy link
Member

Would probably be good to add a test for print=None, that might prompt codecov to correct itself.

@seirl
Copy link
Contributor Author

seirl commented Sep 11, 2017

Okay, rather than adding a new test I updated one that already contained print=lambda *args: None.

@@ -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.

@asvetlov asvetlov merged commit 8a85651 into aio-libs:master Sep 12, 2017
@asvetlov
Copy link
Member

Thanks!

@lock
Copy link

lock bot commented Oct 28, 2019

This thread has been automatically locked since there has not been
any recent activity after it was closed. Please open a new issue for
related bugs.

If you feel like there's important points made in this discussion,
please include those exceprts into that new issue.

@lock lock bot added the outdated label Oct 28, 2019
@lock lock bot locked as resolved and limited conversation to collaborators Oct 28, 2019
@psf-chronographer psf-chronographer bot added the bot:chronographer:provided There is a change note present in this PR label Oct 28, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bot:chronographer:provided There is a change note present in this PR outdated
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants