@@ -149,7 +149,7 @@ kinds of expressions much simpler while being predictable and doing
149149the correct things intuitively. Using these operators, the function
150150could instead be written as:
151151
152- ::
152+ .. code-block :: py823
153153
154154 def get_customer_name(data: Data) -> str | None:
155155 return data.customer?.user?.name.lower()
@@ -198,7 +198,7 @@ least for dictionaries a useful helper method is ``dict.get(key)``.
198198
199199 Writing it using ``?. `` and ``?[ ] `` would look like this:
200200
201- ::
201+ .. code-block :: py823
202202
203203 def get_customer_name(data: Data) -> str | None:
204204 return data.get("customer")?["user"]?["name"].lower()
@@ -221,14 +221,14 @@ hide in plain sight. Attribute and function names have been shortened.
221221 If code relied on this property, the expression cannot necessarily
222222 be replaced with ``?. `` or ``?[ ] ``.
223223
224- ::
224+ .. code-block :: py823
225225
226226 # In assignments
227227
228228 x = a.b if (a is not None) else None
229229 x = a?.b
230230
231- ::
231+ .. code-block :: py823
232232
233233 # In if statements often used as guard clause with early
234234 # return or raising of an exception
@@ -242,7 +242,7 @@ hide in plain sight. Attribute and function names have been shortened.
242242 if a is None or a.b is None: ...
243243 if a?.b is None: ...
244244
245- ::
245+ .. code-block :: py823
246246
247247 # Misc expressions
248248
@@ -336,7 +336,7 @@ for trying to get a subscript of ``None`` are omitted. It is therefore
336336not necessary to change subsequent ``. `` or ``[ ] `` on the right-hand
337337side just because a ``?. `` or ``?[ ] `` is used prior.
338338
339- ::
339+ .. code-block :: py823-console
340340
341341 >>> a = None
342342 >>> print(a?.b.c[0].some_function())
@@ -348,7 +348,7 @@ their ``None``-aware counterparts, and call expressions). As a rule of
348348thumb, short-circuiting is broken once an operator other than
349349``. ``, ``[ ] ``, ``?. ``, ``?[ ] `` is reached.
350350
351- ::
351+ .. code-block :: py823-console
352352
353353 >>> a = None
354354 >>> print(a?.b.c)
@@ -370,7 +370,7 @@ be broken. For example function arguments or subscripts are evaluated
370370on their own and would not short-circuit the remaining ``tail `` of the
371371outer expression.
372372
373- ::
373+ .. code-block :: py823
374374
375375 # func(a?.b).c[d?.e]
376376
@@ -389,7 +389,7 @@ if ``a is None``. This is conceptually identical to extracting the group
389389contents and storing the result in a temporary variable before
390390substituting it back into the original expression.
391391
392- ::
392+ .. code-block :: py823
393393
394394 # (a?.b).c
395395
@@ -400,7 +400,7 @@ Common use cases for ``None``-aware access operators in groups are
400400boolean or conditional expressions which can provide a fallback value
401401in case the first part evaluates to ``None ``.
402402
403- ::
403+ .. code-block :: py823
404404
405405 (a.b?.c or d).e?.func()
406406
@@ -419,7 +419,7 @@ Assignments
419419``None ``-aware expressions may only be used in a ``Load `` context.
420420Assignments are not permitted and will raise a ``SyntaxError ``.
421421
422- ::
422+ .. code-block :: py823-console
423423
424424 >>> a?.b = 1
425425 File "<python-input-1>", line 1
@@ -437,7 +437,7 @@ This does not apply if the ``None``-aware expressions is only part
437437of a larger expression and evaluated on its own, for example as a
438438function argument.
439439
440- ::
440+ .. code-block :: py823-console
441441
442442 >>> a = None
443443 >>> def f(a):
@@ -512,7 +512,7 @@ their needs, especially code formatters might prefer a style which
512512conforms better to their existing preferences. An example of what
513513is possible:
514514
515- ::
515+ .. code-block :: py823
516516
517517 def get_customer_name(data: Data) -> str | None:
518518 return (
@@ -675,7 +675,7 @@ because it might be too difficult to understand. Developers should
675675instead change any subsequent attribute access or subscript to their
676676``None ``-aware variants.
677677
678- ::
678+ .. code-block :: py823
679679
680680 # before
681681 a.b.optional?.c.d.e
@@ -706,7 +706,7 @@ instead of two new operators, it may also be **too general**, in a sense
706706that it can be combine with any other operator. For example it is not
707707clear what the following expressions would mean:
708708
709- ::
709+ .. code-block :: py823-console
710710
711711 >>> x? + 1
712712 >>> x? -= 1
@@ -717,7 +717,7 @@ clear what the following expressions would mean:
717717 Even if a default meaning of ``is not None else None `` is assumed, the
718718expressions are likely to raise errors at some point.
719719
720- ::
720+ .. code-block :: py823-console
721721
722722 >>> x? + 1
723723 >>> (_t1 if ((_t1 := x) is not None) else None) + 1
@@ -896,7 +896,7 @@ the substitution principle. An expression ``(a?.b).c`` should behave
896896the same whether or not ``a?.b `` is written inline inside a group or
897897defined as a separate variable.
898898
899- ::
899+ .. code-block :: py823
900900
901901 (a?.b).c
902902
@@ -1053,7 +1053,7 @@ for an ``optional`` value evaluates to ``None``, the result will be
10531053will be skipped. In the example below, if ``a.b `` is ``None ``, so will
10541054be ``a.b?.c ``:
10551055
1056- ::
1056+ .. code-block :: py823
10571057
10581058 a.b?.c
10591059 ^^^
0 commit comments