This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author gregory.p.smith
Recipients gregory.p.smith, vstinner
Date 2020-12-16.01:01:15
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1608080475.81.0.714965710626.issue42648@roundup.psfhosted.org>
In-reply-to
Content
We could also be thinking too low level here.  We don't have to re-use returncode for this or do it on POpen itself.  This could be done at the `run()` API level and CompletedProcess could be given state indicating success or failure of the exec itself.

ex: Add a `capture_oserror=` arg to `run()`.

```
>>> proc = subprocess.run(['foo'], capture_oserror=True)
>>> proc
CompletedProcess(args='foo', oserror=FileNotFoundError(2, 'No such file or directory'))
>>> if proc.failure:
...   
```

Add two properties to CompletedProcess:

```
@property
def success(self):
    return bool(self.oserror is None and not self.returncode)

@property
def failure(self):
    return bool(self.oserror or self.returncode)
```

to make using that an easy one liner.

Another thing that came up recently was someone wishing CompletedProcess had a `__bool__()` method.  I rejected that as it could break existing code already testing None vs CompletedProcess via truthiness.  But such a desire should be satisfied with the above .success and .failure properties.
History
Date User Action Args
2020-12-16 01:01:15gregory.p.smithsetrecipients: + gregory.p.smith, vstinner
2020-12-16 01:01:15gregory.p.smithsetmessageid: <1608080475.81.0.714965710626.issue42648@roundup.psfhosted.org>
2020-12-16 01:01:15gregory.p.smithlinkissue42648 messages
2020-12-16 01:01:15gregory.p.smithcreate