4 ms·
PEP 0505 – None coalescing operators
- dalke 11y agoI can kinda see the need for "x ?? default", but the "Null-Aware Member Access Operator" and "Null-Aware Index Access Operator" should have examples of how it would improve code. The text gives an example of current code: data = [] if data is None else data then argues: > This particular formulation has the undesirable effect of putting the operands in an unintuitive order: the brain thinks, "use data if possible and use [] as a fallback," but the code puts the fallback _before_ the preferred value. I tried, but I don't see this as unintuitive. I would like more than the proposer's intuition as justification. Eg, is there any evidence that developers or reviewers have a tendency to confuse these by accident?