summaryrefslogtreecommitdiff
path: root/Lib/subprocess.py
diff options
context:
space:
mode:
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>2020-12-24 21:18:37 -0800
committerGitHub <noreply@github.com>2020-12-24 21:18:37 -0800
commit7acfe4125725e86c982300cf10c0ab791a0783f4 (patch)
tree2c9445799a0c06d3878802a0d230a34508890bac /Lib/subprocess.py
parent5a6b5d8c392ca7028e7c034710a89492cd704778 (diff)
downloadcpython-git-7acfe4125725e86c982300cf10c0ab791a0783f4.tar.gz
bpo-42388: Fix subprocess.check_output input=None when text=True (GH-23467)
When the modern text= spelling of the universal_newlines= parameter was added for Python 3.7, check_output's special case around input=None was overlooked. So it behaved differently with universal_newlines=True vs text=True. This reconciles the behavior to be consistent and adds a test to guarantee it. Also clarifies the existing check_output documentation. Co-authored-by: Alexey Izbyshev <izbyshev@ispras.ru> (cherry picked from commit 64abf373444944a240274a9b6d66d1cb01ecfcdd) Co-authored-by: Gregory P. Smith <greg@krypto.org>
Diffstat (limited to 'Lib/subprocess.py')
-rw-r--r--Lib/subprocess.py6
1 files changed, 5 insertions, 1 deletions
diff --git a/Lib/subprocess.py b/Lib/subprocess.py
index f1d829a6f1..ddf1128fdd 100644
--- a/Lib/subprocess.py
+++ b/Lib/subprocess.py
@@ -415,7 +415,11 @@ def check_output(*popenargs, timeout=None, **kwargs):
if 'input' in kwargs and kwargs['input'] is None:
# Explicitly passing input=None was previously equivalent to passing an
# empty string. That is maintained here for backwards compatibility.
- kwargs['input'] = '' if kwargs.get('universal_newlines', False) else b''
+ if kwargs.get('universal_newlines') or kwargs.get('text'):
+ empty = ''
+ else:
+ empty = b''
+ kwargs['input'] = empty
return run(*popenargs, stdout=PIPE, timeout=timeout, check=True,
**kwargs).stdout