]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
bpo-40497: Fix handling of check in subprocess.check_output() (GH-19897)
authorRémi Lapeyre <remi.lapeyre@lenstra.fr>
Mon, 20 Sep 2021 15:09:05 +0000 (17:09 +0200)
committerGitHub <noreply@github.com>
Mon, 20 Sep 2021 15:09:05 +0000 (17:09 +0200)
Co-authored-by: Tal Einat <taleinat@gmail.com>
Co-authored-by: Łukasz Langa <lukasz@langa.pl>
Lib/subprocess.py
Lib/test/test_subprocess.py
Misc/NEWS.d/next/Library/2020-10-18-09-42-53.bpo-40497.CRz2sG.rst [new file with mode: 0644]

index dd1174ee59ad3b880afdbfcfe3f5035c64a20ba5..33f022f8fced6649f00c2e3f7e3561611c862f6d 100644 (file)
@@ -405,8 +405,9 @@ def check_output(*popenargs, timeout=None, **kwargs):
     decoded according to locale encoding, or by "encoding" if set. Text mode
     is triggered by setting any of text, encoding, errors or universal_newlines.
     """
-    if 'stdout' in kwargs:
-        raise ValueError('stdout argument not allowed, it will be overridden.')
+    for kw in ('stdout', 'check'):
+        if kw in kwargs:
+            raise ValueError(f'{kw} argument not allowed, it will be overridden.')
 
     if 'input' in kwargs and kwargs['input'] is None:
         # Explicitly passing input=None was previously equivalent to passing an
index 87967ca7f3c93df15eba4da3d7e7da553670cb26..3af523e8346c462a70cb5f5829593c41dcf3aaab 100644 (file)
@@ -171,6 +171,14 @@ class ProcessTestCase(BaseTestCase):
                 [sys.executable, "-c", "print('BDFL')"])
         self.assertIn(b'BDFL', output)
 
+        with self.assertRaisesRegex(ValueError,
+                "stdout argument not allowed, it will be overridden"):
+            subprocess.check_output([], stdout=None)
+
+        with self.assertRaisesRegex(ValueError,
+                "check argument not allowed, it will be overridden"):
+            subprocess.check_output([], check=False)
+
     def test_check_output_nonzero(self):
         # check_call() function with non-zero return code
         with self.assertRaises(subprocess.CalledProcessError) as c:
diff --git a/Misc/NEWS.d/next/Library/2020-10-18-09-42-53.bpo-40497.CRz2sG.rst b/Misc/NEWS.d/next/Library/2020-10-18-09-42-53.bpo-40497.CRz2sG.rst
new file mode 100644 (file)
index 0000000..067c486
--- /dev/null
@@ -0,0 +1,4 @@
+:meth:`subprocess.check_output` now raises :exc:`ValueError` when the
+invalid keyword argument *check* is passed by user code. Previously
+such use would fail later with a :exc:`TypeError`.
+Patch by Rémi Lapeyre.