Message383109
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. |
|
Date |
User |
Action |
Args |
2020-12-16 01:01:15 | gregory.p.smith | set | recipients:
+ gregory.p.smith, vstinner |
2020-12-16 01:01:15 | gregory.p.smith | set | messageid: <1608080475.81.0.714965710626.issue42648@roundup.psfhosted.org> |
2020-12-16 01:01:15 | gregory.p.smith | link | issue42648 messages |
2020-12-16 01:01:15 | gregory.p.smith | create | |
|