[Python-ideas] PEP 505 (None coalescing operators) thoughts

Andrew Barnert abarnert at yahoo.com
Tue Sep 29 12:11:30 CEST 2015

On Sep 28, 2015, at 22:55, Greg Ewing <greg.ewing at canterbury.ac.nz> wrote:
> Guido van Rossum wrote:
>> On Mon, Sep 28, 2015 at 12:47 PM, Andrew Barnert <abarnert at yahoo.com <mailto:abarnert at yahoo.com>> wrote:
>>        Expr(
>>            value=Attribute(
>>                value=Attribute(
>>                    value=Name(id='spam'), attr='eggs', uptalk=True),
>>                attr='cheese', uptalk=False))
>> Hm, I think the problem is that this way of representing the tree encourages thinking that each attribute (with or without ?) can be treated on its own.
> It's hard to think of any other way of representing this in
> an AST that makes the short-circuiting behaviour any clearer.
> I suspect that displaying an AST isn't really going to be
> helpful as a way of documenting the semantics. Because the
> semantics aren't really in the AST itself, they're in the
> compiler code that interprets the AST.

That's why I gave both an AST and the bytecode (and how it differs from the AST and bytecode with non-uptalked attribution). I think that makes it obvious and unambiguous what the semantics are, to anyone who knows how the compiler handles attribution ASTs, and understands the resulting bytecode.

Of course, as Guido points out, that "anyone who..." is a pretty restricted set, so maybe this wasn't as useful as I intended, and we have to wait for someone to write up the details in a way that's still unambiguous, but also human-friendly.

More information about the Python-ideas mailing list