Gregory P. Smith <g...@krypto.org> added the comment:
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. ---------- _______________________________________ Python tracker <rep...@bugs.python.org> <https://bugs.python.org/issue42648> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com