Skip to content

Commit 1e001da

Browse files
committed
Additional improvements
1 parent e402514 commit 1e001da

1 file changed

Lines changed: 9 additions & 5 deletions

File tree

peps/pep-0998.rst

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -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``.
126126
Errors can occur though if the variable being checked can be falsy for
127127
values 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

130131
The "``None`` coalescing" operator can bridge this gab by adding an
131132
alternative 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
226227
rule which previously referenced the ``disjunction`` rule is updated
227228
to refer to the ``coalesce`` rule instead.
228229

229-
::
230+
.. code-block:: PEG
230231
231232
coalesce:
232233
| disjunction ('??' disjunction)+
@@ -270,7 +271,7 @@ Grammar changes
270271
A new ``??=`` token is added. Additionally, the ``assignment`` rule
271272
is 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
350351
characters.
351352

352353
In 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
354355
like ``otherwise`` could be added, they do not convey an inherit
355356
meaning 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
357358
languages.
358359

359360
Lastly, 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

420424
Proliferation of ``None`` in code bases

0 commit comments

Comments
 (0)