Black: stdout is not utilized properly (output going to stderr)

Created on 28 Feb 2020  ·  6Comments  ·  Source: psf/black

Describe the bug A clear and concise description of what the bug is.

To Reproduce Steps to reproduce the behavior:

$ black  file.py
All done! ✨ 🍰 ✨
1 file left unchanged.

$ black  2>/dev/null file.py

Expected behavior A clear and concise description of what you expected to happen.

$ black  file.py
All done! ✨ 🍰 ✨
1 file left unchanged.

$ black  2>/dev/null file.py
All done! ✨ 🍰 ✨
1 file left unchanged.

Environment (please complete the following information):

  • Version: Ubuntu 19.10b0
  • OS and Python version: Ubuntu 18.04 / Python 3.6.9
bug design

Most helpful comment

Why what? Do you not understand why someone might want to differentiate between stdout and stderr? I'm sure there's tons or pubic writing on the matter. Here's the top result google returned to me: https://www.jstorimer.com/blogs/workingwithcode/7766119-when-to-use-stderr-instead-of-stdout

All 6 comments

why?

Why what? Do you not understand why someone might want to differentiate between stdout and stderr? I'm sure there's tons or pubic writing on the matter. Here's the top result google returned to me: https://www.jstorimer.com/blogs/workingwithcode/7766119-when-to-use-stderr-instead-of-stdout

The Black output in these examples is similar to the diagnostic messages cited in that blog post, and therefore a better fit for stderr than stdout.

Black does use stdout for printing its formatted output:

$ echo '1+2' | black -
1 + 2
reformatted -
All done! ✨ 🍰 ✨
1 file reformatted.
$ echo '1+2' | black - 2>/dev/null
1 + 2

but... its not an error. How does this not fall squarely into stdout territory? Its simply informative output generated by a _successful_ execution of the program. Am I missing something? Apologies if I am.

So I took a look at this. I kind of go both ways here. I personally would like black to respect UNIX philosophies and have non error output go to stdout and all error output to stderr.

Basically there are only 3 main changes (but I have not looked at why the tests are failing completely):

  • Change the non quiet/verbose success All done! ✨ 🍰 ✨ output to go to stdout
  • make the DebugVisitor use err() partial
  • Change out click.secho partial to default to stdout

The failing commit can be seen here: https://github.com/psf/black/commit/b3e5ea576a5b725731f0c6eb69be5534795fffbd

  • If people agree with it I'll go and look at the tests and fix them
  • As I said I'm partial and just wanted to explore this before closing the issue

Change the non quiet/verbose success All done! ✨ 🍰 ✨ output to go to stdout

If this change was made, doesn't that break the ability to use Black in a pipeline?

source_generator (eg echo "1+2") | black >generated_source.py

A user doesn't want the generated source to contain "All done!" messages.

The unix philosophy is not just that errors alone go to stderr. All user-readable status messages should go there, to separate them from the data being operated on.

Was this page helpful?
0 / 5 - 0 ratings