[Python-checkins] bpo-34886: Fix subprocess.run handling of exclusive arguments (GH-11727)

Miss Islington (bot) webhook-mailer at python.org
Sat Jun 8 11:15:11 EDT 2019


https://github.com/python/cpython/commit/6324ac1293b2cf71559869b88f89f510f9a62a8e
commit: 6324ac1293b2cf71559869b88f89f510f9a62a8e
branch: 3.8
author: Miss Islington (bot) <31488909+miss-islington at users.noreply.github.com>
committer: GitHub <noreply at github.com>
date: 2019-06-08T08:15:02-07:00
summary:

bpo-34886: Fix subprocess.run handling of exclusive arguments (GH-11727)


Fix an unintended ValueError from :func:`subprocess.run` when checking for
conflicting `input` and `stdin` or `capture_output` and `stdout` or `stderr` args
when they were explicitly provided but with `None` values within a passed in
`**kwargs` dict rather than as passed directly by name.
(cherry picked from commit 8cc605acdda5aff250ab4c9b524a7560f90ca9f3)

Co-authored-by: Rémi Lapeyre <remi.lapeyre at henki.fr>

files:
A Misc/NEWS.d/next/Library/2019-06-08-16-03-19.bpo-34886.Ov-pc9.rst
M Lib/subprocess.py

diff --git a/Lib/subprocess.py b/Lib/subprocess.py
index 9e36b9de6b34..d34c57828b48 100644
--- a/Lib/subprocess.py
+++ b/Lib/subprocess.py
@@ -459,12 +459,12 @@ def run(*popenargs,
     The other arguments are the same as for the Popen constructor.
     """
     if input is not None:
-        if 'stdin' in kwargs:
+        if kwargs.get('stdin') is not None:
             raise ValueError('stdin and input arguments may not both be used.')
         kwargs['stdin'] = PIPE
 
     if capture_output:
-        if ('stdout' in kwargs) or ('stderr' in kwargs):
+        if kwargs.get('stdout') is not None or kwargs.get('stderr') is not None:
             raise ValueError('stdout and stderr arguments may not be used '
                              'with capture_output.')
         kwargs['stdout'] = PIPE
diff --git a/Misc/NEWS.d/next/Library/2019-06-08-16-03-19.bpo-34886.Ov-pc9.rst b/Misc/NEWS.d/next/Library/2019-06-08-16-03-19.bpo-34886.Ov-pc9.rst
new file mode 100644
index 000000000000..1b5fc3702521
--- /dev/null
+++ b/Misc/NEWS.d/next/Library/2019-06-08-16-03-19.bpo-34886.Ov-pc9.rst
@@ -0,0 +1,5 @@
+Fix an unintended ValueError from :func:`subprocess.run` when checking for
+conflicting `input` and `stdin` or `capture_output` and `stdout` or `stderr`
+args when they were explicitly provided but with `None` values within a
+passed in `**kwargs` dict rather than as passed directly by name. Patch
+contributed by Rémi Lapeyre.



More information about the Python-checkins mailing list