Skip to content

Fix bug in fix_print.py fixer - #596

Merged
edschofield merged 1 commit into
PythonCharmers:masterfrom
abjonnes:fix-print-trailing-comma
Nov 11, 2021
Merged

Fix bug in fix_print.py fixer#596
edschofield merged 1 commit into
PythonCharmers:masterfrom
abjonnes:fix-print-trailing-comma

Conversation

@abjonnes

@abjonnes abjonnes commented Nov 11, 2021

Copy link
Copy Markdown

When the print ends with a non-space whitespace character, an extra
space character should not be printed at the end.

From the python2 documentation:

A space is written before each object is (converted and) written, unless the output system believes it is positioned at the beginning of a line. This is the case (1) when no characters have yet been written to standard output, (2) when the last character written to standard output is a whitespace character except ' ', or (3) when the last write operation on standard output was not a print statement.

The changes here don't do this perfectly (e.g. when a printed string variable ends with a tab), but capture the common case of when a literal string which ends in a tab or line feed is printed with a trailing comma, like print "something\t",.

Addresses (at least partially) #473.

When the print ends with a non-space whitespace character, an extra
space character should not be printed at the end.
@edschofield
edschofield merged commit 17e4bbd into PythonCharmers:master Nov 11, 2021
@edschofield

Copy link
Copy Markdown
Contributor

Many thanks, @abjonnes !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

2 participants