Earlier quoted context omitted.
Here are some examples from the Python standard library: multiprocessing/pool.py: self._number_left = length//chunksize + bool(length % chunksize) test/test_math.py: tmant = tmant // (2*h) + bool(tmant & h and tmant & 3*h-1) From NumPy and SciPy: numpy-1.11.0/tools/swig/test/testArray.py:385: sys.exit(bool(result.errors + result.failures)) scipy/scipy/signal/signaltools.py:2003: n_out = n_out // down + bool(n_out % d…
Looks like the libraries use the technique to handle those conditional off-by-one situations that other languages might resolve with a ternary expression. Thanks!
unittest2/compatibility.py:25:
if bool(unc_path) ^ bool(unc_start):
scipy/signal/fir_filter_design.py:266:
pass_nyquist = bool(cutoff.size & 1) ^ pass_zero
pypysrc/py/_path/common.py:65:
if bool(value) ^ bool(meth()) ^ invert:
There's also a place where the bool is turned into an int, but that extra conversion isn't actually needed - the following would work without the int() call: scipy/stats/morestats.py:2083:
correction = 0.5 * int(bool(correction)) * np.sign(T - mn)