diff --git a/Doc/library/subprocess.rst b/Doc/library/subprocess.rst index e9ba15eec1c20bd..bab14d71b9aa12d 100644 --- a/Doc/library/subprocess.rst +++ b/Doc/library/subprocess.rst @@ -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 diff --git a/Lib/subprocess.py b/Lib/subprocess.py index dffcda3e9fbbc0a..f9628690ba5a4a1 100644 --- a/Lib/subprocess.py +++ b/Lib/subprocess.py @@ -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)] diff --git a/Misc/NEWS b/Misc/NEWS index 4413c511157fcd1..de7d01ddb0d6898 100644 --- a/Misc/NEWS +++ b/Misc/NEWS @@ -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.