Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions Doc/library/subprocess.rst
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,12 @@ compatibility with older versions, see the :ref:`call-function-trio` section.

.. versionadded:: 3.5

.. method:: __bool__()

Returns True if :attr:`returncode` is zero, otherwise False.

.. versionadded:: 3.7

.. data:: DEVNULL

Special value that can be used as the *stdin*, *stdout* or *stderr* argument
Expand Down
4 changes: 4 additions & 0 deletions Lib/subprocess.py
Original file line number Diff line number Diff line change
Expand Up @@ -355,6 +355,10 @@ def __init__(self, args, returncode, stdout=None, stderr=None):
self.stdout = stdout
self.stderr = stderr

def __bool__(self):
""" Returns True if the exit code is zero; otherwise False."""
return self.returncode == 0

def __repr__(self):
args = ['args={!r}'.format(self.args),
'returncode={!r}'.format(self.returncode)]
Expand Down
3 changes: 3 additions & 0 deletions Misc/NEWS
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,9 @@ Extension Modules
Library
-------

- bpo-25452: Add __bool__() method to subprocess.CompletedProcess. Patch by
Sayan Chowdhury

- Issue #16285: urrlib.parse.quote is now based on RFC 3986 and hence includes
'~' in the set of characters that is not quoted by default. Patch by
Christian Theune and Ratnadeep Debnath.
Expand Down