[Updated] [+ ] D9059: procutil: assign stdio objects if they are None

quark (Jun Wu) phabricator at mercurial-scm.org
Sat Oct 3 02:45:18 UTC 2020


quark updated this revision to Diff 23030.

REPOSITORY
  rHG Mercurial

CHANGES SINCE LAST UPDATE
  https://phab.mercurial-scm.org/D9059?vs=22741&id=23030

BRANCH
  default

CHANGES SINCE LAST ACTION
  https://phab.mercurial-scm.org/D9059/new/

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

AFFECTED FILES
  mercurial/utils/procutil.py
  tests/test-stdio-missing.t

CHANGE DETAILS

diff --git a/tests/test-stdio-missing.t b/tests/test-stdio-missing.t
new file mode 100644
--- /dev/null
+++ b/tests/test-stdio-missing.t
@@ -0,0 +1,13 @@
+  $ cat > prompt.py << 'EOF'
+  > from mercurial import exthelper
+  > eh = exthelper.exthelper()
+  > cmdtable = eh.cmdtable
+  > @eh.command(b'prompt', [], norepo=True)
+  > def prompt(ui):
+  >     chosen = ui.promptchoice(b"is stdin present? (y/N) $$ &Yes $$ &No", default=1)
+  >     ui.write(b"chosen: %d\n" % chosen)
+  > EOF
+
+  $ hg --config extensions.prompt=prompt.py prompt 0<&-
+  is stdin present? (y/N)  n
+  chosen: 1
diff --git a/mercurial/utils/procutil.py b/mercurial/utils/procutil.py
--- a/mercurial/utils/procutil.py
+++ b/mercurial/utils/procutil.py
@@ -114,6 +114,11 @@
 
 
 if pycompat.ispy3:
+    # Stdio objects can be 'None' on Python 3. Most code paths (for example,
+    # dispatch.initstdio) do not expect that.
+    sys.stdin = sys.stdin or io.TextIOWrapper(io.BytesIO())
+    sys.stdout = sys.stdout or io.TextIOWrapper(io.BytesIO())
+    sys.stderr = sys.stderr or io.TextIOWrapper(io.BytesIO())
     # Python 3 implements its own I/O streams.
     # TODO: .buffer might not exist if std streams were replaced; we'll need
     # a silly wrapper to make a bytes stream backed by a unicode one.



To: quark, #hg-reviewers
Cc: indygreg, mjacob, mercurial-patches
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mercurial-scm.org/pipermail/mercurial-patches/attachments/20201003/4b38bb19/attachment.html>


More information about the Mercurial-patches mailing list