[Python-Dev] What's the status of PEP 505: None-aware operators?
Serhiy Storchaka
storchaka at gmail.com
Wed Nov 29 03:06:32 EST 2017
28.11.17 22:31, Raymond Hettinger пише:
>> I also cc python-dev to see if anybody here is strongly in favor or against this inclusion.
>
> Put me down for a strong -1. The proposal would occasionally save a few keystokes but comes at the expense of giving Python a more Perlish look and a more arcane feel.
>
> One of the things I like about Python is that I can walk non-programmers through the code and explain what it does. The examples in PEP 505 look like a step in the wrong direction. They don't "look like Python" and make me feel like I have to decrypt the code to figure-out what it does.
>
> timeout ?? local_timeout ?? global_timeout
> 'foo' in (None ?? ['foo', 'bar'])
> requested_quantity ?? default_quantity * price
> name?.strip()[4:].upper()
> user?.first_name.upper()
New syntax often look unusual. "lambda" and "yield" also didn't "look
like Python".
But there are other considerations.
1. Languages that has the ?? and ?. operators usually have a single
special (or at least a one obvious) value that is served for signaling
"there-is-no-a-value". The None in Python is not so special. It can be
used as a common object, and other ways can be used for denoting an
"absent" value. The need of None-specific operators in Python is lower.
2. Python already have other ways for handling "absent" values: the
short-circuit "or" and "and" operators which return the one of
arguments, getattr() with the default value, the hack with default class
attributes, exception handling. The need of the proposed operators in
Python is lower.
3. These languages usually have borrowed the syntax of the ternary
operator from C: "... ? ... : ...". Thus the syntax with "?" looks more
natural in them. But in Python it looks less natural.
I'm -1 for accepting this syntax in 3.7. In future all can be changed.
More information about the Python-Dev
mailing list