Re:Python has brought computer programming to a vast new aud...
by politician on Friday July 20, 2018 @01:55PM
(#17577266)
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!
[ Parent
| on HN ]
Re:Python has brought computer programming to a vast new aud...
by eesmith on Friday July 20, 2018 @04:15PM
(#17578536)
FWIW, 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)