Issue 33339: Using default encoding with subprocess.run() is not obvious (original) (raw)

It is possible to use subprocess.run() with the system's default encoding by using universal_newlines=True. This is very handy, but it's not at all obvious (at least for me) that setting such option has effect on encoding. This is especially true when the docs don't explain this explicitly:

"""If encoding or errors are specified, or universal_newlines is true, file objects for stdin, stdout and stderr are opened in text mode using the specified encoding and errors or the io.TextIOWrapper default."""

This is such a useful feature that it ought to be documented better, preferably with an example.

From code reading point of view, I would also consider encoding=True to be more explicit that universal_newlines=True. I can submit a separate issue about that if others feel the same.

This issue was already addressed for 3.x in bpo-31756, which added the a text parameter and updated the documentation. As to 2.7, it was officially retired as of the first of this month. Anyway, I don't think there was a pressing need to clarify the documentation in 2.7.