r/Python • u/Ninteendo19d0 • 49m ago
News PEP 824: None-coalescing operators is approved
The Steering Council has decided to accept PEP 824 (on the condition that the ??= operator is removed, leaving only the ?? operator in the proposal).
Old: lst = [] if lst is None else lst
New: lst = lst ?? []
Discussion thread: https://discuss.python.org/t/pep-824-none-coalescing-operators/109161/93
The decision on PEP 823 – None-aware access operators is still pending.
40
Upvotes
•
u/TPECKA180 36m ago
I like this addition, especially because
orisn't always a safe replacement for an explicit None check. Sometimes 0, False, or an empty list are perfectly valid values.The
??operator makes that distinction much clearer without adding unnecessary verbosity. I'm also curious to see what happens with PEP 823.•
u/Sin-nie 45m ago
Am I missing something but can't you already do this with 'or'?
•
u/shiningmatcha 11m ago
such good news!
•
u/skjall 33m ago
The none-aware access operators is the big one, really hoping it gets in soon. This is nice too of course!