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

Chris Angelico rosuav at gmail.com
Wed Nov 29 17:40:14 EST 2017


On Thu, Nov 30, 2017 at 8:56 AM, Stephan Houben <stephanh42 at gmail.com> wrote:
>
>
> Op 29 nov. 2017 22:35 schreef "Greg Ewing" <greg.ewing at canterbury.ac.nz>:
>
>
> It would read better with some kind of pronoun in there:
>
>    A if it is not None else C
>
> Hypercard's Hypertalk had a special variable "it" that
> worked sort of like that.
>
>
> I  considered that,  but there are two issues.
>
> 1. Backward-incompatible change
>
> 2. The semantics of
> A if B else C
> now depends on if B contains 'it',
> in which case A gets evaluated unconditionally and prior to B.
> What if evaluation of 'it' is itself conditional, e.g.
>
> print("hello") if a or it else print("goodbye")
>
> Note that in the
>
> A if <binary_relation> B else C
>
> proposal the evaluation of the implicit 'it' is never conditional in that
> way.

The only way would be for "it" to be a keyword. You can't misinterpret
"A if pass is not None else C", or "A if def is not None else C", as
they're currently syntax errors. Obviously we don't want the word "it"
to become a keyword (massive breakage right there), and I'm pretty
sure there's no existing keyword that actually makes sense here, so
this proposal would depend on coming up with a useful word that
wouldn't collide too much. I'm -0.9 unless someone can find the
perfect word.

ChrisA


More information about the Python-ideas mailing list