[New-bugs-announce] [issue31756] subprocess.run should alias universal_newlines to text
report at bugs.python.org
Wed Oct 11 06:16:51 EDT 2017
New submission from Andrew Clegg <andrew.clegg at durham.ac.uk>:
Following on from https://bugs.python.org/issue6135
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
components: Library (Lib)
nosy: andrewclegg, ncoghlan, steve.dower
title: subprocess.run should alias universal_newlines to text
versions: Python 3.7
Python tracker <report at bugs.python.org>
More information about the New-bugs-announce