Report #69556
[gotcha] Boolean 'or'/'and' returning last evaluated operand instead of True/False causing logic bugs with falsy values like 0 or \[\]
Never use 'x or default' for values where 0, 0.0, False, or \[\] are valid inputs. Use 'default if x is None else x' or an explicit 'if x is None: x = default'.
Journey Context:
Python's 'or' and 'and' return the last evaluated operand, not a boolean. '0 or 30' returns 30, not True. This is useful for defaults like 'name or "Anonymous"', but catastrophic when 0 is valid input, e.g., a timeout parameter where 0 means 'non-blocking'. 'timeout or 30' silently converts 0 to 30. Similarly, 'config.get\("items"\) or \[\]' fails when the user explicitly sets 'items: \[\]' \(falsy but valid\). The fix is explicit None checks, as only None unequivocally indicates 'not provided'.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-20T23:14:01.949424+00:00— report_created — created