diff options
author | Miss Islington (bot) <31488909+miss-islington@users.noreply.github.com> | 2022-10-05 03:35:53 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-10-05 03:35:53 (GMT) |
commit | ece5f7e04600150712d88b928b76d0f2de5f5011 (patch) | |
tree | d9273b80e3b276c68cb734dd12041646e581bf32 /Lib | |
parent | 24908f1f207f4642fc57ae79c69a3dcb0770a96a (diff) | |
download | cpython-ece5f7e04600150712d88b928b76d0f2de5f5011.zip cpython-ece5f7e04600150712d88b928b76d0f2de5f5011.tar.gz cpython-ece5f7e04600150712d88b928b76d0f2de5f5011.tar.bz2 |
gh-97825: fix AttributeError when calling subprocess.check_output(input=None) with encoding or errors args (GH-97826)
* fix AttributeError, add unit test
(cherry picked from commit db64fb9bbe92b212db7dd173f787ea3607ae971a)
Co-authored-by: andrei kulakov <andrei.avk@gmail.com>
Diffstat (limited to 'Lib')
-rw-r--r-- | Lib/subprocess.py | 3 | ||||
-rw-r--r-- | Lib/test/test_subprocess.py | 6 |
2 files changed, 8 insertions, 1 deletions
diff --git a/Lib/subprocess.py b/Lib/subprocess.py index a414321..e5d7f09 100644 --- a/Lib/subprocess.py +++ b/Lib/subprocess.py @@ -411,7 +411,8 @@ 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. - if kwargs.get('universal_newlines') or kwargs.get('text'): + if kwargs.get('universal_newlines') or kwargs.get('text') or kwargs.get('encoding') \ + or kwargs.get('errors'): empty = '' else: empty = b'' diff --git a/Lib/test/test_subprocess.py b/Lib/test/test_subprocess.py index b91791a..ea02a9e 100644 --- a/Lib/test/test_subprocess.py +++ b/Lib/test/test_subprocess.py @@ -227,6 +227,12 @@ class ProcessTestCase(BaseTestCase): input=None, universal_newlines=True) self.assertNotIn('XX', output) + def test_check_output_input_none_encoding_errors(self): + output = subprocess.check_output( + [sys.executable, "-c", "print('foo')"], + input=None, encoding='utf-8', errors='ignore') + self.assertIn('foo', output) + def test_check_output_stdout_arg(self): # check_output() refuses to accept 'stdout' argument with self.assertRaises(ValueError) as c: |