Skip to content

Commit 4d2957c

Browse files
remilapeyretaleinatambv
authored
bpo-40497: Fix handling of check in subprocess.check_output() (GH-19897)
Co-authored-by: Tal Einat <[email protected]> Co-authored-by: Łukasz Langa <[email protected]>
1 parent ef9e22b commit 4d2957c

File tree

3 files changed

+15
-2
lines changed

3 files changed

+15
-2
lines changed

Lib/subprocess.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -405,8 +405,9 @@ def check_output(*popenargs, timeout=None, **kwargs):
405405
decoded according to locale encoding, or by "encoding" if set. Text mode
406406
is triggered by setting any of text, encoding, errors or universal_newlines.
407407
"""
408-
if 'stdout' in kwargs:
409-
raise ValueError('stdout argument not allowed, it will be overridden.')
408+
for kw in ('stdout', 'check'):
409+
if kw in kwargs:
410+
raise ValueError(f'{kw} argument not allowed, it will be overridden.')
410411

411412
if 'input' in kwargs and kwargs['input'] is None:
412413
# Explicitly passing input=None was previously equivalent to passing an

Lib/test/test_subprocess.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,14 @@ def test_check_output(self):
171171
[sys.executable, "-c", "print('BDFL')"])
172172
self.assertIn(b'BDFL', output)
173173

174+
with self.assertRaisesRegex(ValueError,
175+
"stdout argument not allowed, it will be overridden"):
176+
subprocess.check_output([], stdout=None)
177+
178+
with self.assertRaisesRegex(ValueError,
179+
"check argument not allowed, it will be overridden"):
180+
subprocess.check_output([], check=False)
181+
174182
def test_check_output_nonzero(self):
175183
# check_call() function with non-zero return code
176184
with self.assertRaises(subprocess.CalledProcessError) as c:
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
:meth:`subprocess.check_output` now raises :exc:`ValueError` when the
2+
invalid keyword argument *check* is passed by user code. Previously
3+
such use would fail later with a :exc:`TypeError`.
4+
Patch by Rémi Lapeyre.

0 commit comments

Comments
 (0)