It's not a bug.

Since 0 is falsy value, `0 or 2` is 2, not 0.
You need to use `prev if prev < curr else curr` instead of `cond and A or B` hack.