classification
Title: subprocess.run throws exception when input and stdin are passed as kwargs
Type: behavior Stage: commit review
Components: Library (Lib) Versions: Python 3.9, Python 3.8, Python 3.7
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: gregory.p.smith Nosy List: aecant, gregory.p.smith, josh.r, miss-islington, remi.lapeyre, serhiy.storchaka
Priority: normal Keywords: patch, patch, patch

Created on 2018-10-03 18:50 by aecant, last changed 2019-06-11 04:55 by gregory.p.smith. This issue is now closed.

Files
File name Uploaded Description Edit
subprocess_run_bug.py aecant, 2018-10-03 18:50 Minimal working example
Pull Requests
URL Status Linked Edit
PR 11727 merged remi.lapeyre, 2019-02-01 22:49
PR 11727 merged remi.lapeyre, 2019-02-01 22:49
PR 11727 merged remi.lapeyre, 2019-02-01 22:49
PR 13916 merged miss-islington, 2019-06-08 14:56
PR 13917 merged miss-islington, 2019-06-08 14:56
Messages (11)
msg327002 - (view) Author: Alessandro (aecant) * Date: 2018-10-03 18:50
If input and stdin parameters are passed as keyword arguments to subprocess.run, an exception is thrown even if input and stdin are both None.

The exception is ValueError: stdin and input arguments may not both be used.

I attach a minimal working example of the bug
msg327003 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2018-10-03 19:12
What is wrong with this?
msg327004 - (view) Author: Alessandro (aecant) * Date: 2018-10-03 19:22
subprocess.run('ls', input=b'', stdin=None) # this is ok

kwargs = {'input': b'', 'stdin': None}
subprocess.run('ls', **kwargs) # this throws exception

The two calls should have the same behaviour, but one throws exception and the other doesn't. I think the exception shouldn't be thrown, because stdin is None.
msg327008 - (view) Author: Josh Rosenberg (josh.r) * (Python triager) Date: 2018-10-03 19:49
I just tried:

    subprocess.run('ls', input=b'', stdin=None)

and I got the same ValueError as for passing using kwargs. Where did you get the idea subprocess.run('ls', input=b'', stdin=None) worked?
msg327009 - (view) Author: Josh Rosenberg (josh.r) * (Python triager) Date: 2018-10-03 19:52
The actual code receives input by name, but stdin is received in **kwargs. The test is just:

    if input is not None:
        if 'stdin' in kwargs:
            raise ValueError(...)
        kwargs['stdin'] = PIPE

Perhaps just change `if 'stdin' in kwargs:` to:

    if kwargs.get('stdin') is not None:

so it obeys the documented API (that says stdin defaults to None, and therefore passing stdin=None explicitly should be equivalent to not passing it at all)?
msg327011 - (view) Author: Alessandro (aecant) * Date: 2018-10-03 20:06
> and I got the same ValueError as for passing using kwargs. Where did you get the idea subprocess.run('ls', input=b'', stdin=None) worked?

Sorry, the example was wrong. Both calls have the same behaviour.

> so it obeys the documented API (that says stdin defaults to None, and therefore passing stdin=None explicitly should be equivalent to not passing it at all)?

The actual problem is this. The fix you propose works for me.
msg334728 - (view) Author: Rémi Lapeyre (remi.lapeyre) * Date: 2019-02-01 22:50
I opened a PR with @josh.r proposed change.
msg345042 - (view) Author: Gregory P. Smith (gregory.p.smith) * (Python committer) Date: 2019-06-08 14:56
New changeset 8cc605acdda5aff250ab4c9b524a7560f90ca9f3 by Gregory P. Smith (Rémi Lapeyre) in branch 'master':
bpo-34886: Fix subprocess.run handling of exclusive arguments (GH-11727)
https://github.com/python/cpython/commit/8cc605acdda5aff250ab4c9b524a7560f90ca9f3
msg345046 - (view) Author: miss-islington (miss-islington) Date: 2019-06-08 15:15
New changeset 6324ac1293b2cf71559869b88f89f510f9a62a8e by Miss Islington (bot) in branch '3.8':
bpo-34886: Fix subprocess.run handling of exclusive arguments (GH-11727)
https://github.com/python/cpython/commit/6324ac1293b2cf71559869b88f89f510f9a62a8e
msg345049 - (view) Author: miss-islington (miss-islington) Date: 2019-06-08 15:24
New changeset 10b4fd98142edef6ab7b034e10ae5c9551043999 by Miss Islington (bot) in branch '3.7':
bpo-34886: Fix subprocess.run handling of exclusive arguments (GH-11727)
https://github.com/python/cpython/commit/10b4fd98142edef6ab7b034e10ae5c9551043999
msg345179 - (view) Author: Gregory P. Smith (gregory.p.smith) * (Python committer) Date: 2019-06-11 04:55
thanks!
History
Date User Action Args
2019-06-11 04:55:33gregory.p.smithsetstatus: open -> closed

assignee: gregory.p.smith
versions: + Python 3.8, Python 3.9
keywords: patch, patch, patch
resolution: fixed
messages: + msg345179
stage: patch review -> commit review
2019-06-08 15:24:13miss-islingtonsetmessages: + msg345049
2019-06-08 15:15:10miss-islingtonsetnosy: + miss-islington
messages: + msg345046
2019-06-08 14:56:42miss-islingtonsetpull_requests: + pull_request13790
2019-06-08 14:56:35miss-islingtonsetpull_requests: + pull_request13789
2019-06-08 14:56:27gregory.p.smithsetnosy: + gregory.p.smith
messages: + msg345042
2019-02-01 22:50:04remi.lapeyresetnosy: + remi.lapeyre
messages: + msg334728
2019-02-01 22:49:14remi.lapeyresetkeywords: + patch
stage: patch review
pull_requests: + pull_request11613
2019-02-01 22:49:07remi.lapeyresetkeywords: + patch
stage: (no value)
pull_requests: + pull_request11612
2019-02-01 22:49:00remi.lapeyresetkeywords: + patch
stage: (no value)
pull_requests: + pull_request11611
2018-10-03 20:06:56aecantsetmessages: + msg327011
2018-10-03 19:52:55josh.rsetmessages: + msg327009
2018-10-03 19:49:29josh.rsetnosy: + josh.r
messages: + msg327008
2018-10-03 19:22:57aecantsetmessages: + msg327004
2018-10-03 19:12:16serhiy.storchakasetnosy: + serhiy.storchaka
messages: + msg327003
2018-10-03 18:50:38aecantcreate