[Python-Dev] What's the status of PEP 505: None-aware operators?

Nick Coghlan ncoghlan at gmail.com
Wed Nov 29 01:11:31 EST 2017


On 29 November 2017 at 07:15, Mark Haase <mehaase at gmail.com> wrote:
> Hi Lukasz, I don’t have plans on editing or promoting the PEP any further,
> unless there is renewed interest or somebody proposes a more Pythonic
> syntax.

We should probably set the state of both this and the related circuit
breaking protocol PEPs to Deferred so folks know neither of us is
actually working on them.

While I still think there's merit to the idea of making it easier to
write concise data cleanup pipelines in Python, I find the argument
"The currently proposed spelling doesn't even come close to reading
like executable pseudo code" to be a compelling one.

I think a big part of the problem is that these kinds of data cleanup
operations don't even have a good *vocabulary* around them yet, so
nobody actually knows how to write them as pseudo code in the first
place - we only know how to express them in particular programming
languages.

Trying to come up with pseudo code for the example cases Raymond mentioned:

   timeout if defined, else local_timeout if defined, else global_timeout
   price * (requested_quantity if defined, else default_quantity)

   name if not defined, else name.strip()[4:].upper()
   user if not defined, else name.first_name.upper()

And that's not actually that different to their current spellings in Python:

   timeout if timeout is not None else local_timeout if local_timeout
is not None, else global_timeout
   price * (requested_quantity if requested_quantity is not None else
default_quantity)

   name if name is None else name.strip()[4:].upper()
   user if user is None else name.first_name.upper()

One key aspect that Python does miss relative to the pseudocode
versions is that we don't actually have a term for "expr is not None".
"def" is used specifically for functions, so "defined" isn't reference
right. References to "None" are bound like anything else, so "bound"
isn't right. "exists" probably comes closest (hence the title of the
withdrawn PEP 531).

That said, if we did decide to allow "def" in a conditional expression
to mean "defined" in the "lhs is not None" sense, it would look like:

   timeout if def else local_timeout if def else global_timeout
   price * (requested_quantity if def else default_quantity)

   name if not def else name.strip()[4:].upper()
   user if not def else user.first_name.upper()

Cheers,
Nick.

P.S. Compared to this, our last symbolic feature addition (matrix
multiplication), was a relatively straightforward transcription of "⋅"
to "@", just as regular multiplication is a transcription of "×" to
"*".

-- 
Nick Coghlan   |   ncoghlan at gmail.com   |   Brisbane, Australia


More information about the Python-Dev mailing list