@@ -125,7 +125,8 @@ Python will check for truthiness instead of comparing the value to
125125``None ``. It frequently works fine as ``None `` evaluates to ``False ``.
126126Errors can occur though if the variable being checked can be falsy for
127127values other then ``None ``, too. Common ones include ``0 ``, ``"" ``,
128- ``[] ``, ``{} ``, ``() `` or custom objects which overwrite ``__bool__ ``.
128+ ``() ``, ``[] ``, ``{} ``, ``set() `` or custom objects which overwrite
129+ ``__bool__ ``.
129130
130131The "``None `` coalescing" operator can bridge this gab by adding an
131132alternative to ``or `` which explicitly checks only for ``None `` values.
@@ -226,7 +227,7 @@ A new ``??`` token is added, as well as a new ``coalesce`` rule. Every
226227rule which previously referenced the ``disjunction `` rule is updated
227228to refer to the ``coalesce `` rule instead.
228229
229- ::
230+ .. code-block :: PEG
230231
231232 coalesce:
232233 | disjunction ('??' disjunction)+
@@ -270,7 +271,7 @@ Grammar changes
270271A new ``??= `` token is added. Additionally, the ``assignment `` rule
271272is extended to include the coalesce assignment.
272273
273- ::
274+ .. code-block :: PEG
274275
275276 assignment:
276277 | NAME ':' expression ['=' annotated_rhs]
@@ -350,10 +351,10 @@ reader. Not to mention they are also quite short with just two and three
350351characters.
351352
352353In comparison a new (soft-) keyword would likely not enjoy the same
353- benefits. There is no short established name for it, so while ideas
354+ benefits. There is no established short name for it, so while ideas
354355like ``otherwise `` could be added, they do not convey an inherit
355356meaning and therefore do not provide an immediate benefit. In contrast,
356- the ``?? `` operator is well established in other major programming
357+ the ``?? `` operator is well known in other major programming
357358languages.
358359
359360Lastly, using a (soft-) keyword for the "coalescing assignment" operator
@@ -411,10 +412,13 @@ using the coalescing operators. To summarize them again:
411412
412413- They help avoid repeating the variable expression or having to
413414 introduce a temporary variable.
415+
414416- Clear control flow, no more ``if ... is not None else ... `` and the
415417 inverse ``if ... is None else ... `` in the same code blocks.
418+
416419- Avoids the often (mis-) used ``or `` to provide fallback values
417420 just for ``None ``.
421+
418422- More concise while also being more explicit.
419423
420424Proliferation of ``None `` in code bases
0 commit comments