[issue42468] subprocess.CompletedProcess: Add boolean value

Gregory P. Smith report at bugs.python.org
Thu Nov 26 01:57:20 EST 2020


Gregory P. Smith <greg at krypto.org> added the comment:

My concern with this as an API change is if anyone is returning or passing a CompletedProcess instance around it may well be used in a context where None is a potential value.  Existing code in that situation would ordinarily be doing a bare `if cp:` test on it to check for None.

I don't ordinarily see code that passes a CompletedProcess instance around... but it seems like an annoying potentially breaking change to make for a very small added value.

`if cp.returncode:` is very explicit about its intent when read or written.  

`if cp:` is not, and could even be misread by someone unaware of the API to assume that cp is a number most likely the returncode itself and misunderstand that as "the returncode was non-zero" when it really means the opposite.

If we had done this on day one of the run() -> CompletedProcess API this would've been a fine choice.  But changing it now doesn't seem like a good idea to me.

----------
versions:  -Python 3.9

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue42468>
_______________________________________


More information about the Python-bugs-list mailing list