2 ms·
Looks like the libraries use the technique to handle those conditional off-by-one situations that other languages might resolve with a ternary expression. Than
by politician 8y ago
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!
- eesmith 8y agoFWIW, I only searched for lines containing 'bool(' and '+'. That means I missed some of the other uses, like: 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)