D2450: util: handle fileno() on Python 3 throwing io.UnsupportedOperation

durin42 (Augie Fackler) phabricator at mercurial-scm.org
Mon Feb 26 01:02:37 EST 2018


durin42 created this revision.
Herald added a subscriber: mercurial-devel.
Herald added a reviewer: hg-reviewers.

REVISION SUMMARY
  Fortunately, the exception exists on Python 2 so we don't have to do
  something weirder than this.

REPOSITORY
  rHG Mercurial

REVISION DETAIL
  https://phab.mercurial-scm.org/D2450

AFFECTED FILES
  mercurial/util.py

CHANGE DETAILS

diff --git a/mercurial/util.py b/mercurial/util.py
--- a/mercurial/util.py
+++ b/mercurial/util.py
@@ -26,6 +26,7 @@
 import gc
 import hashlib
 import imp
+import io
 import itertools
 import mmap
 import os
@@ -1178,7 +1179,10 @@
 
 def _isstdout(f):
     fileno = getattr(f, 'fileno', None)
-    return fileno and fileno() == sys.__stdout__.fileno()
+    try:
+        return fileno and fileno() == sys.__stdout__.fileno()
+    except io.UnsupportedOperation:
+        return False # fileno() raised UnsupportedOperation
 
 def shellenviron(environ=None):
     """return environ with optional override, useful for shelling out"""



To: durin42, #hg-reviewers
Cc: mercurial-devel


More information about the Mercurial-devel mailing list