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

Random832 random832 at fastmail.com
Tue Sep 29 04:22:09 CEST 2015


On Mon, Sep 28, 2015, at 17:48, Guido van Rossum 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.

How else would you represent it? Maybe some sort of expression that
represents a _list_ of attribute/item/call "operators" that are each
applied, and if one of them results in none and has uptalk=True it can
yield early.

Something like...

AtomExpr(atom=Name('spam'), trailers=[Attribute('eggs', uptalk=True),
Attribute('cheese', uptalk=False)])

For a more complex example:

a?.b.c?[12](34).f(56)?(78)

AtomExpr(Name('a'), [
	Attribute('b', True),
	Attribute('c', False),
	Subscript(12, True),
	Call([34], False),
	Attribute('f', False),
	Call([56], False),
	Call([78], True)])

I almost sent this with it called "Thing", but I checked the grammar and
found an element this thing actually maps to.


More information about the Python-ideas mailing list