New submission from Andrew Clegg <andrew.cl...@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)
messages: 304125
nosy: andrewclegg, ncoghlan, steve.dower
priority: normal
severity: normal
status: open
title: subprocess.run should alias universal_newlines to text
type: enhancement
versions: Python 3.7

_______________________________________
Python tracker <rep...@bugs.python.org>
<https://bugs.python.org/issue31756>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to