Patchwork windows: handle file-like objects without isatty() method

login
register
mail settings
Submitter Manuel Jacob
Date July 17, 2020, 1:22 p.m.
Message ID <aa6621ba3a4871256c15.1594992155@tmp>
Download mbox | patch
Permalink /patch/46792/
State Accepted
Headers show

Comments

Manuel Jacob - July 17, 2020, 1:22 p.m.
# HG changeset patch
# User Manuel Jacob <me@manueljacob.de>
# Date 1594990702 -7200
#      Fri Jul 17 14:58:22 2020 +0200
# Node ID aa6621ba3a4871256c15bb7b87e8e5dfe940ad0f
# Parent  a37f290a71240b851f5df900833f848efbab576a
# EXP-Topic winstdout
windows: handle file-like objects without isatty() method

Copying the function is not nice, but moving around stuff to avoid the
circular import didn’t seem to be worth the effort.
Yuya Nishihara - July 18, 2020, 10 a.m.
On Fri, 17 Jul 2020 15:22:35 +0200, Manuel Jacob wrote:
> # HG changeset patch
> # User Manuel Jacob <me@manueljacob.de>
> # Date 1594990702 -7200
> #      Fri Jul 17 14:58:22 2020 +0200
> # Node ID aa6621ba3a4871256c15bb7b87e8e5dfe940ad0f
> # Parent  a37f290a71240b851f5df900833f848efbab576a
> # EXP-Topic winstdout
> windows: handle file-like objects without isatty() method

Queued, thanks.

Patch

diff --git a/mercurial/windows.py b/mercurial/windows.py
--- a/mercurial/windows.py
+++ b/mercurial/windows.py
@@ -186,6 +186,14 @@ 
 listdir = osutil.listdir
 
 
+# copied from .utils.procutil, remove after Python 2 support was dropped
+def _isatty(fp):
+    try:
+        return fp.isatty()
+    except AttributeError:
+        return False
+
+
 class winstdout(object):
     '''Some files on Windows misbehave.
 
@@ -197,7 +205,7 @@ 
 
     def __init__(self, fp):
         self.fp = fp
-        self.throttle = not pycompat.ispy3 and fp.isatty()
+        self.throttle = not pycompat.ispy3 and _isatty(fp)
 
     def __getattr__(self, key):
         return getattr(self.fp, key)