On Python 3, use more flexible encoding to send bytes to stdout#2398
Merged
On Python 3, use more flexible encoding to send bytes to stdout#2398
Conversation
This is a little ugly. Eventually, it would be nice to create a single output stream set up with the appropriate encoding settings *at startup* and use that repeatedly, instead of having `print_` check the settings every time. This output stream could be cleanly replaced with a mock harness for testing. Yet another reason to desire a big "beets context" object...
Member
Author
|
Well, at least the tests pass! Does this seem crazy to you, @jrobeson? |
|
wouldn't the test harness break in the same way when run by the user with a |
Member
Author
|
Hmm, I don't quite see how... in the tests under Python 3, this change makes it so the locale encoding isn't used at all (everything just stays as |
sampsyo
added a commit
that referenced
this pull request
Mar 7, 2017
On Python 3, use more flexible encoding to send bytes to stdout
antlarr
pushed a commit
to antlarr/beets
that referenced
this pull request
May 8, 2017
Pointed out in beetbox#2490, this is a regression introduced by beetbox#2398. We need to flush the buffer to faithfully emulate the "real" print() function.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
As explained in #2393, the last big issue in Python 3 is that
printorsys.stdout.writecan crash depending on the system's locale configuration. This change restores the Python 2 behavior, which avoids potential crashes by (a) using thereplaceerror handler and (b) allowing the user to override the stdout encoding in the configuration.Unfortunately, this breaks out test harnesses that capture stdout. One way to work around this might be to detect when we're in a test harness and just record the text strings directly.