PEP 824 proposes None-coalescing operators for Python
The ?? and ??= forms would supply defaults only when a value is None, and can be accepted independently of related None-aware access syntax.
Python may gain dedicated operators for None defaults under PEP 824, which proposes a None-coalescing operator ?? and a None-coalescing assignment operator ??=.
The design is a precise alternative to the common or pattern. Where a or b substitutes whenever the left side is falsy, a ?? b would evaluate and return the right side only when the left side is exactly None. The assignment form would set a target only if it currently holds None. Both are framed as short-circuit equivalents of an is not None check, not a truthiness test.
That limit is intentional. The PEP rejects broader handling of falsy values or arbitrary sentinels, aiming to stop the accidental loss of legitimate data such as 0 or empty strings when developers reach for or. PEP 824 is a split successor to the older PEP 505. Its companion, PEP 823, covers None-aware attribute and subscript access; the author confirmed either PEP could be accepted without the other.
Early reaction on discuss.python.org has been largely supportive of the None-only scope. Commenters said the operators would cut repetitive None tests in code that wraps optional and nested API data, and would make intent clearer than or when falsy values must be preserved. Several argued that extending the operators to custom missing markers would recreate the pitfalls of overriding truthiness.
Surface questions remain. Precedence is set beside or and conditional expressions, following the arrangement used in languages such as JavaScript and C#, with parentheses left optional when that order matches intent. On spelling, the author noted that almost every language with coalescing operators uses ?? and ??=, and that a doubled character, like && and ||, marks them as conditional forms distinct from single-character bitwise operators. A suggestion to add dunder hooks so classes could redefine the check for their own sentinels falls outside the proposal's current narrow focus.