Patchwork windows: don’t set `softspace` attribute in `winstdout`

login
register
mail settings
Submitter Manuel Jacob
Date July 18, 2020, 10:36 a.m.
Message ID <5251fb1632f517aac454.1595068567@tmp>
Download mbox | patch
Permalink /patch/46803/
State New
Headers show

Comments

Manuel Jacob - July 18, 2020, 10:36 a.m.
# HG changeset patch
# User Manuel Jacob <me@manueljacob.de>
# Date 1595068555 -7200
#      Sat Jul 18 12:35:55 2020 +0200
# Node ID 5251fb1632f517aac4542a8ea0b5c300ffaadebe
# Parent  10f48720ef95af8a7c22a7b7c21b3fa0534866f0
# EXP-Topic remove_softspace
windows: don’t set `softspace` attribute in `winstdout`

Python 2 file objects have the `softspace` attribute
(https://docs.python.org/2/library/stdtypes.html#file.softspace), which is used
by the print statement to track its internal state. The documentation demands
from file-like objects only that the attribute is writable and initialized to
0. Method `file.write()` sets it to 0, but this is not documented.
Historically, sys.stdout was replaced by an instance of the `winstdout` class,
so it needed to behave exactly the same (the softspace fix was introduced in
705278e70457). Nowadays we don’t replace sys.stdout and don’t use the print
statement on `winstdout` instances, so we can safely drop it.
Yuya Nishihara - July 18, 2020, 11:13 a.m.
On Sat, 18 Jul 2020 12:36:07 +0200, Manuel Jacob wrote:
> # HG changeset patch
> # User Manuel Jacob <me@manueljacob.de>
> # Date 1595068555 -7200
> #      Sat Jul 18 12:35:55 2020 +0200
> # Node ID 5251fb1632f517aac4542a8ea0b5c300ffaadebe
> # Parent  10f48720ef95af8a7c22a7b7c21b3fa0534866f0
> # EXP-Topic remove_softspace
> windows: don’t set `softspace` attribute in `winstdout`
> 
> Python 2 file objects have the `softspace` attribute
> (https://docs.python.org/2/library/stdtypes.html#file.softspace), which is used
> by the print statement to track its internal state. The documentation demands
> from file-like objects only that the attribute is writable and initialized to
> 0. Method `file.write()` sets it to 0, but this is not documented.
> Historically, sys.stdout was replaced by an instance of the `winstdout` class,
> so it needed to behave exactly the same (the softspace fix was introduced in
> 705278e70457). Nowadays we don’t replace sys.stdout and don’t use the print
> statement on `winstdout` instances, so we can safely drop it.

Good archaeology. Queued, thanks.

Patch

diff --git a/mercurial/windows.py b/mercurial/windows.py
--- a/mercurial/windows.py
+++ b/mercurial/windows.py
@@ -209,8 +209,6 @@ 
             pass
 
     def write(self, s):
-        if not pycompat.ispy3:
-            self.softspace = 0
         try:
             if not self.throttle:
                 return self.fp.write(s)