Skip to content

Commit 732a99b

Browse files
committed
Minor changes
1 parent 56a58b5 commit 732a99b

File tree

1 file changed

+9
-9
lines changed

1 file changed

+9
-9
lines changed

peps/pep-0823.rst

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,11 @@ to:
2323

2424
.. code-block:: python
2525
26-
# a.b?.c
27-
_t.c if ((_t := a.b) is not None) else None
26+
# a.b?.c.d
27+
_t.c.d if ((_t := a.b) is not None) else None
2828
29-
# a.b?[c]
30-
_t[c] if ((_t := a.b) is not None) else None
29+
# a.b?[c].d
30+
_t[c].d if ((_t := a.b) is not None) else None
3131
3232
See the `Specification`_ section for more details.
3333

@@ -89,7 +89,7 @@ Nested objects with ``optional`` attributes
8989
-------------------------------------------
9090

9191
When writing Python code, it is common to encounter objects with ``optional``
92-
attributes. Accessing attributes, subscript or function calls can raise
92+
attributes. Accessing attributes, subscripts or function calls can raise
9393
``AttributeError`` or ``TypeError`` at runtime if the value is ``None``.
9494
Several common patterns have developed to ensure these operations will
9595
not raise. The goal for ``?.`` and ``?[ ]`` is to make reading and writing
@@ -377,6 +377,7 @@ hide in plain sight. Attribute and function names have been shortened.
377377

378378
if not (a and a.b == val): ...
379379
if not (a?.b == val): ...
380+
if a?.b != val: ...
380381

381382
if not (a and a.lower()): ...
382383
if not a?.lower(): ...
@@ -469,7 +470,7 @@ subsequent ``.`` or ``[ ]`` on the right hand side just because a
469470

470471
The ``None``-aware access operators will only short-circuit expressions
471472
containing name, attribute access, subscript, their ``None``-aware
472-
counterparts and call expressions. As a rule of thumb, short-circuiting
473+
counterparts, and call expressions. As a rule of thumb, short-circuiting
473474
is broken once a (soft-) keyword is reached.
474475

475476
::
@@ -494,7 +495,7 @@ Using ``?.`` and ``?[ ]`` inside groups is possible. In addition to the
494495
rules laid out in the `previous <Short-circuiting_>`_ section,
495496
short-circuiting will also be broken at the end of a group. For example
496497
the expression ``(a?.b).c`` will raise an ``AttributeError`` on ``.c``
497-
if ``a = None``. This is conceptually identical to extracting the group
498+
if ``a is None``. This is conceptually identical to extracting the group
498499
contents and storing the result in a temporary variable before
499500
substituting it back into the original expression.
500501

@@ -550,8 +551,7 @@ must be taken so these can be evaluate properly.
550551
(a?.b or d).c = 1
551552

552553
# This would be evaluated as
553-
_t2 = t1.b if ((t1 := a) is not None) else None
554-
554+
_t2 = _t1.b if ((_t1 := a) is not None) else None
555555
if _t2:
556556
_t2.c = 1
557557
else:

0 commit comments

Comments
 (0)