This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: subprocess.check_output() accept the check keyword argument
Type: behavior Stage: resolved
Components: Library (Lib) Versions: Python 3.11
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Nosy List: christian.heimes, lukasz.langa, remi.lapeyre
Priority: normal Keywords: patch

Created on 2020-05-04 09:54 by remi.lapeyre, last changed 2022-04-11 14:59 by admin. This issue is now closed.

Pull Requests
URL Status Linked Edit
PR 19897 merged remi.lapeyre, 2020-05-04 09:58
Messages (7)
msg368027 - (view) Author: Rémi Lapeyre (remi.lapeyre) * Date: 2020-05-04 09:54
The subprocess.check_output() raises TypeError when given the `check` keyword-argument:

Python 3.8.2 (v3.8.2:7b3ab5921f, Feb 24 2020, 17:52:18) 
[Clang 6.0 (clang-600.0.57)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import subprocess
>>> subprocess.check_output(['ls'], check=False)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/subprocess.py", line 411, in check_output
    return run(*popenargs, stdout=PIPE, timeout=timeout, check=True,
TypeError: run() got multiple values for keyword argument 'check'

It should just use True as the default when it's not specified in kwargs.
msg368029 - (view) Author: Christian Heimes (christian.heimes) * (Python committer) Date: 2020-05-04 10:03
-1

check_output() should not accept check=False. Please only improve the error message. I would be fine with accepting check=True, too
msg368031 - (view) Author: Rémi Lapeyre (remi.lapeyre) * Date: 2020-05-04 10:14
> check_output() should not accept check=False.

I thought about raising ValueError instead but `subprocess.check_output([...], check=False)` is actually a convenient shortcut over `subprocess.run([...], stdout=subprocess.PIPE).stdout` and I can't think of much drawbacks if someone explicitly ask for the check to be disabled. Is there any way we could have that?
msg368032 - (view) Author: Christian Heimes (christian.heimes) * (Python committer) Date: 2020-05-04 10:34
IMHO it's both confusing and bad API design to have a function like

    validate_result(..., validate=False)

Now a reviewer has to check that a developer uses the validate_result() function *and* the developer is not passing validate=False into the function.

GH-19897 is also provides a new feature, so it cannot get into Python 3.7 and 3.8.
msg368035 - (view) Author: Rémi Lapeyre (remi.lapeyre) * Date: 2020-05-04 11:01
> Now a reviewer has to check that a developer uses the validate_result() function *and* the developer is not passing validate=False into the function.

Fair enough, I updated the PR to raise ValueError instead.
msg402239 - (view) Author: Łukasz Langa (lukasz.langa) * (Python committer) Date: 2021-09-20 15:09
New changeset 4d2957c1b9a915f76da418e89bf9b5add141ca3e by Rémi Lapeyre in branch 'main':
bpo-40497: Fix handling of check in subprocess.check_output() (GH-19897)
https://github.com/python/cpython/commit/4d2957c1b9a915f76da418e89bf9b5add141ca3e
msg402240 - (view) Author: Łukasz Langa (lukasz.langa) * (Python committer) Date: 2021-09-20 15:09
Fixed with GH-19897 for Python 3.11. Thanks! ✨ 🍰 ✨
History
Date User Action Args
2022-04-11 14:59:30adminsetgithub: 84677
2021-09-20 15:09:53lukasz.langasetstatus: open -> closed
versions: + Python 3.11, - Python 3.7, Python 3.8, Python 3.9
messages: + msg402240

resolution: fixed
stage: resolved
2021-09-20 15:09:14lukasz.langasetnosy: + lukasz.langa
messages: + msg402239
2020-05-04 11:01:26remi.lapeyresetmessages: + msg368035
2020-05-04 10:34:20christian.heimessetmessages: + msg368032
2020-05-04 10:14:43remi.lapeyresetmessages: + msg368031
2020-05-04 10:03:53christian.heimessetnosy: + christian.heimes

messages: + msg368029
stage: patch review -> (no value)
2020-05-04 09:58:38remi.lapeyresetkeywords: + patch
stage: patch review
pull_requests: + pull_request19208
2020-05-04 09:54:48remi.lapeyrecreate