[Python-ideas] PEP 505: None-aware operators

Antoine Pitrou antoine at python.org
Mon Jul 23 06:29:33 EDT 2018


Le 23/07/2018 à 12:25, Steve Dower a écrit :
> On 23Jul2018 1111, Antoine Pitrou wrote:
>> On Mon, 23 Jul 2018 10:51:31 +0100
>> Steve Dower <steve.dower at python.org> wrote:
>>>
>>> Which is the most important operator?
>>> -------------------------------------
>>>
>>> Personally, I think '?.' is the most valuable.
>>
>> For me, it's the most contentious.  The fact that a single '?' added to
>> a regular line of Python code can short-circuit execution silently is a
>> net detriment to readability, IMHO.
> 
> The only time it would short-circuit is when it would otherwise raise 
> AttributeError for trying to access an attribute from None, which is 
> also going to short-circuit.

But AttributeError is going to bubble up as soon as it's raised, unless
it's explicitly handled by an except block.  Simply returning None may
have silent undesired effects (perhaps even security flaws).

This whole thing reminds of PHP's malicious "@" operator.

Regards

Antoine.


More information about the Python-ideas mailing list