Uh oh!
There was an error while loading. Please reload this page.
gh-63299: Escape unencodable characters in pprint() - #155192
Open
serhiy-storchaka wants to merge 2 commits into
Open
gh-63299: Escape unencodable characters in pprint()#155192serhiy-storchaka wants to merge 2 commits into
serhiy-storchaka wants to merge 2 commits into
Conversation
pprint.pp(), pprint.pprint() and PrettyPrinter.pprint() failed with UnicodeEncodeError if the output could not be encoded in the encoding of the output stream. Such characters are now escaped with backslashes, as sys.displayhook does. The stream is only wrapped if it encodes the written text and uses the strict error handler. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Documentation build overview
|
TextIOWrapper translates "\n" to os.linesep if newline is None. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
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 freeto 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.
pprint.pp(),pprint.pprint()andPrettyPrinter.pprint()failed withUnicodeEncodeErrorif the output could not be encoded in the encoding of the output stream. The output is intended to be read by humans, so it is better to escape unencodable characters than to fail. They are now escaped with backslashes, assys.displayhookdoes.The stream is only wrapped if it encodes the written text and uses the strict error handler, so streams which do not encode the text (like
io.StringIO) and streams with their own error handler are unaffected.pformat()andsaferepr(), which return strings, are unaffected too.