Merge branch 'master' of github.com:python/peps
This commit is contained in:
commit
57ccf32901
13
pep-0505.txt
13
pep-0505.txt
|
@ -613,13 +613,14 @@ those ideas are recorded here.
|
||||||
|
|
||||||
The ``None``-aware syntax applies to attribute and index access, so it seems
|
The ``None``-aware syntax applies to attribute and index access, so it seems
|
||||||
natural to ask if it should also apply to function invocation syntax. It might
|
natural to ask if it should also apply to function invocation syntax. It might
|
||||||
be written as ``foo?()``, where ``foo`` is only called if it is not None. This
|
be written as ``foo?()``, where ``foo`` is only called if it is not None.
|
||||||
idea was quickly rejected, for several reasons.
|
|
||||||
|
|
||||||
First, no other mainstream language has such syntax. Second, Python evaluates
|
This has been rejected on the basis of the proposed operators being intended
|
||||||
arguments to a function before it looks up the function itself, so
|
to aid traversal of partially populated hierarchical data structures, *not*
|
||||||
``foo?(bar())`` would still call ``bar()`` even if ``foo`` is ``None``. This
|
for traversal of arbitrary class hierarchies. This is reflected in the fact
|
||||||
behaviour is unexpected for a so-called "short-circuiting" operator.
|
that none of the other mainstream languages that already offer this syntax
|
||||||
|
have found it worthwhile to support a similar syntax for optional function
|
||||||
|
invocations.
|
||||||
|
|
||||||
``?`` Unary Postfix Operator
|
``?`` Unary Postfix Operator
|
||||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||||
|
|
Loading…
Reference in New Issue