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.

Title: asyncio.create_subprocess_exec doesn't accept pathlib.Path like subprocess does
Type: enhancement Stage: resolved
Components: asyncio Versions: Python 3.8
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Nosy List: asvetlov, lilydjwg, miss-islington, yselivanov
Priority: normal Keywords: patch

Created on 2018-11-14 13:50 by lilydjwg, last changed 2022-04-11 14:59 by admin. This issue is now closed.

Pull Requests
URL Status Linked Edit
PR 13628 merged lilydjwg, 2019-05-28 15:27
Messages (5)
msg329907 - (view) Author: lilydjwg (lilydjwg) * Date: 2018-11-14 13:50
When I pass pathlib.Path to asyncio.create_subprocess_exec I get:

TypeError: program arguments must be a bytes or text string, not PosixPath

It's not so good when subprocess accepts this kind of arguments without issues. So can you add support for this?
msg343701 - (view) Author: Andrew Svetlov (asvetlov) * (Python committer) Date: 2019-05-27 23:15
All we need is `program = os.fspath(program)` in subprocess_exec() method.

Is anybody volunteered to make a patch (with test and docs update, sure)?
msg343729 - (view) Author: lilydjwg (lilydjwg) * Date: 2019-05-28 04:38
> All we need is `program = os.fspath(program)` in subprocess_exec() method.

I don't think so. The arguments could be `pathlib.Path` too.

We can update the `isinstance(arg, (str, bytes))` check so the args pass on to `subprocess.Popen`. It will work in the POSIX part but there is an issue (issue33617, issue31961) in Windows part: subprocess.list2cmdline doesn't accept pathlib.Path.
msg343771 - (view) Author: Andrew Svetlov (asvetlov) * (Python committer) Date: 2019-05-28 12:46
Aha, I see. You are right.
Let's drop checks for cmd/program/args types but left to subprocess do these checks.
This approach avoiding complex checking/converting logic in asyncio itself and reduces code duplication.
msg343864 - (view) Author: miss-islington (miss-islington) Date: 2019-05-29 06:51
New changeset 744c08a9c75a1a53b7a6521fcee3e7c513919ff9 by Miss Islington (bot) (依云) in branch 'master':
bpo-35246: fix support for path-like args in asyncio subprocess (GH-13628)
Date User Action Args
2022-04-11 14:59:08adminsetgithub: 79427
2019-05-29 06:51:26asvetlovsetstatus: open -> closed
resolution: fixed
stage: patch review -> resolved
2019-05-29 06:51:05miss-islingtonsetnosy: + miss-islington
messages: + msg343864
2019-05-28 15:27:13lilydjwgsetkeywords: + patch
stage: patch review
pull_requests: + pull_request13527
2019-05-28 12:46:04asvetlovsetmessages: + msg343771
2019-05-28 04:38:16lilydjwgsetmessages: + msg343729
2019-05-27 23:15:59asvetlovsetversions: + Python 3.8, - Python 3.7
2019-05-27 23:15:13asvetlovsetmessages: + msg343701
2018-11-14 13:50:49lilydjwgcreate