From 7da32ba438d474a2c0412a461200446329484d08 Mon Sep 17 00:00:00 2001 From: andrei kulakov Date: Tue, 4 Oct 2022 03:38:25 -0400 Subject: [PATCH 1/3] fix AttributeError, add unit test --- Lib/subprocess.py | 3 ++- Lib/test/test_subprocess.py | 6 ++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/Lib/subprocess.py b/Lib/subprocess.py index 7ae8df154b481f..760b93b47ebba6 100644 --- a/Lib/subprocess.py +++ b/Lib/subprocess.py @@ -456,7 +456,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 f6854922a5b878..424a4a93b6f972 100644 --- a/Lib/test/test_subprocess.py +++ b/Lib/test/test_subprocess.py @@ -238,6 +238,12 @@ def test_check_output_input_none_universal_newlines(self): 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: From 547db4c98ac68d9d1cea78dc081705b3346cf98e Mon Sep 17 00:00:00 2001 From: "blurb-it[bot]" <43283697+blurb-it[bot]@users.noreply.github.com> Date: Tue, 4 Oct 2022 07:55:21 +0000 Subject: [PATCH 2/3] =?UTF-8?q?=F0=9F=93=9C=F0=9F=A4=96=20Added=20by=20blu?= =?UTF-8?q?rb=5Fit.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../next/Library/2022-10-04-07-55-19.gh-issue-97825.mNdv1l.rst | 1 + 1 file changed, 1 insertion(+) create mode 100644 Misc/NEWS.d/next/Library/2022-10-04-07-55-19.gh-issue-97825.mNdv1l.rst diff --git a/Misc/NEWS.d/next/Library/2022-10-04-07-55-19.gh-issue-97825.mNdv1l.rst b/Misc/NEWS.d/next/Library/2022-10-04-07-55-19.gh-issue-97825.mNdv1l.rst new file mode 100644 index 00000000000000..cd73afa28fa0fb --- /dev/null +++ b/Misc/NEWS.d/next/Library/2022-10-04-07-55-19.gh-issue-97825.mNdv1l.rst @@ -0,0 +1 @@ +Fixes :exc:`AttributeError` when :meth:`subprocess.check_output` is used with argument `input=None` and either of the arguments *encoding* or *errors* are used. From 1129f49c87fc5b653214e678579af63793818002 Mon Sep 17 00:00:00 2001 From: andrei kulakov Date: Tue, 4 Oct 2022 03:57:04 -0400 Subject: [PATCH 3/3] Update 2022-10-04-07-55-19.gh-issue-97825.mNdv1l.rst --- .../next/Library/2022-10-04-07-55-19.gh-issue-97825.mNdv1l.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Misc/NEWS.d/next/Library/2022-10-04-07-55-19.gh-issue-97825.mNdv1l.rst b/Misc/NEWS.d/next/Library/2022-10-04-07-55-19.gh-issue-97825.mNdv1l.rst index cd73afa28fa0fb..4633dce7b663e7 100644 --- a/Misc/NEWS.d/next/Library/2022-10-04-07-55-19.gh-issue-97825.mNdv1l.rst +++ b/Misc/NEWS.d/next/Library/2022-10-04-07-55-19.gh-issue-97825.mNdv1l.rst @@ -1 +1 @@ -Fixes :exc:`AttributeError` when :meth:`subprocess.check_output` is used with argument `input=None` and either of the arguments *encoding* or *errors* are used. +Fixes :exc:`AttributeError` when :meth:`subprocess.check_output` is used with argument ``input=None`` and either of the arguments *encoding* or *errors* are used.