Skip to content

bpo-31756: subprocess.run should alias universal_newlines to text#4049

Merged
gpshead merged 3 commits intopython:masterfrom
andyclegg:master
Oct 23, 2017
Merged

bpo-31756: subprocess.run should alias universal_newlines to text#4049
gpshead merged 3 commits intopython:masterfrom
andyclegg:master

Conversation

@andyclegg
Copy link
Copy Markdown
Contributor

@andyclegg andyclegg commented Oct 19, 2017

Adds text=False as a keyword-only argument to subprocess.Popen.
Introduces a Popen attribute text_mode and sets this based on
encoding/errors/universal_newlines/text arguments.

https://bugs.python.org/issue31756

Adds text=False as a keyword-only argument to subprocess.Popen.
Introduces a Popen attribute text_mode and sets this based on
encoding/errors/universal_newlines/text arguments.
Comment thread Doc/library/subprocess.rst Outdated

.. versionchanged:: 3.7

Added *text* parameter, as alias of *universal_newlines*
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added the text parameter, as a more understandable alias of universal_newlines.

Comment thread Lib/subprocess.py Outdated
startupinfo=None, creationflags=0,
restore_signals=True, start_new_session=False,
pass_fds=(), *, encoding=None, errors=None):
pass_fds=(), *, encoding=None, errors=None, text=False):
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Change the defaults for universal_newlines and text from False to None.

and in the code below, raise an error when both are supplied but disagree:

if (text is not None and universal_newlines is not None
    and bool(universal_newlines) != bool(text)):
    raise SubprocessError('Cannot disambiguate when both text '
                          'and universal_newlines are supplied but different. '
                          'Pass one or the other.')

Comment thread Lib/subprocess.py
self.stderr = None
self.pid = None
self.returncode = None
self.universal_newlines = universal_newlines
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The universal_newlines instance attribute is part of the public API of the class (even though not documented).

We should keep the name around. Even if it is turned into a property with a setter and getter that ultimately sets/returns the value of the new self.text_mode attribute.

Comment thread Lib/subprocess.py Outdated

communicate() returns a tuple (stdout, stderr). These will be
bytes or, if self.universal_newlines was True, a string.
bytes or, if self.universal_newlines/self.text was True, a string.
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

self.text_mode?

@bedevere-bot
Copy link
Copy Markdown

A Python core developer has requested some changes be made to your pull request before we can consider merging it. If you could please address their requests along with any other requests in other reviews from core developers that would be appreciated.

Once you have made the requested changes, please leave a comment on this pull request containing the phrase I have made the requested changes; please review again. I will then notify any core developers who have left a review that you're ready for them to take another look at this pull request.

@gpshead gpshead self-assigned this Oct 20, 2017
Check for any contradictions between universal_newlines and text arguments.
@andyclegg
Copy link
Copy Markdown
Contributor Author

Thanks for your feedback. I've made the changes you suggested, and had another go at the documentation for Popen/run/communicate to make it a bit more consistent.

I have made the requested changes; please review again.

@bedevere-bot
Copy link
Copy Markdown

Thanks for making the requested changes!

@gpshead: please review the changes made to this pull request.

@gpshead
Copy link
Copy Markdown
Member

gpshead commented Oct 23, 2017

thanks for this, universal_newlines has been an ugly wart of a name in the API for a long long time. :)

@gpshead gpshead added the type-feature A feature request or enhancement label Oct 23, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

type-feature A feature request or enhancement

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants