[Python-ideas] Extending expressions using ellipsis

Shane Hathaway shane at hathawaymix.org
Thu Sep 1 01:24:33 EDT 2016


On 08/31/2016 07:25 PM, Guido van Rossum wrote:
> On Wed, Aug 31, 2016 at 2:46 PM, Shane Hathaway <shane at hathawaymix.org> wrote:
> [...]
>> I'd like to suggest a small change to the Python parser that would make long
>> expressions read better:
>>
>> rows = dbsession.query(Table1) ...
>>     .join(
>>         Table2, Table2.y = Table1.y)
>>     .filter(Table1.x = xx)
>>     .all()
>>
>> [...]
> (And no, this isn't equivalent to using '\'.)

Exactly.

> Would this be enforced in the grammar or by the lexer? Since you say
> you expect the indentation to be enforced, that suggests it would be
> done by the grammar, but then the question is how you would modify the
> grammar? You could take the rule that says an expression can be
> followed by ".NAME" and extended it to also allow "... INDENT xxxxx
> DEDENT" where the xxxxx is whatever's allowed at ".NAME" (i.e. ".NAME"
> followed by other tails like "(......)" or "[.......]".
>
> But then you could only use this new idea for chaining method calls,
> and not for spreading other large expressions across multiple lines.

Yes, I was hoping the enhancement might be useful for more than just 
chaining method calls; if possible, the ellipsis should be allowed 
between any expression tokens.

I'll study the grammar and see if my idea fits cleanly somehow. Thanks!

Shane



More information about the Python-ideas mailing list