You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
assignee='https://github.com/gpshead'closed_at=<Date2017-10-23.02:03:49.650>created_at=<Date2017-10-11.10:16:51.865>labels= ['3.7', 'type-feature', 'library']
title='subprocess.run should alias universal_newlines to text'updated_at=<Date2017-10-23.02:03:49.649>user='https://github.com/andyclegg'
The subprocess module by default returns bytes from subprocess calls. It has a text mode, but this can only be accessed by slightly tangential arguments (setting encoding, errors or universal_newlines).
ncoghlan notes in msg304118 that this is a similar situation to the binary/text mode settings for open(). From the docs " In text mode, if encoding is not specified the encoding used is platform dependent: locale.getpreferredencoding(False) is called to get the current locale encoding"
The universal_newlines argument now effectively just turns on the text mode, however this is not an intuitively and obviously discoverable. So to improve usability, and to mirror the file opening behaviour, subprocess calls should be *explicitly* dual mode (binary/text), and have an explicitly named argument to control this.
My enhancement suggestion is as follows:
Add a text=True/False argument that is an alias of universal_newlines, to improve the API.
Clearly document that this implies that the encoding will be guessed, and that an explicit encoding can be given if the guess is wrong
For completeness, the following changes could also be made, although these may be controversial
Remove/deprecate the universal_newlines argument
Revert the default mode to text (as in Python 2.7), and have a binary=True argument instead
As far as docs phrasing goes, it probably makes sense to frame it as "text" being the preferred argument name in 3.7+, with "universal_newlines" retained indefinitely as a compatibility preserving alias. After all, if that wasn't our intention, we wouldn't be adding the more straightforward alias in the first place.
As a new Py3-only argument, "text" can also be made keyword-only. (The Popen arg list is so long that most folks treat everything other than the first item as keyword-only anyway, but it doesn't hurt to ask the interpreter to enforce that)