8000 gh-97825: fix AttributeError when calling subprocess.check_output(input=None) with encoding or errors args by akulakov · Pull Request #97826 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

gh-97825: fix AttributeError when calling subprocess.check_output(input=None) with encoding or errors args #97826

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
fix AttributeError, add unit test
  • Loading branch information
akulakov committed Oct 4, 2022
commit 7da32ba438d474a2c0412a461200446329484d08
3 changes: 2 additions & 1 deletion Lib/subprocess.py
Original file line number Diff line number Diff line change
Expand Up @@ -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''
Expand Down
6 changes: 6 additions & 0 deletions Lib/test/test_subprocess.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
0