<div dir="ltr">Guido's time machine strikes again, though using a slash (\) rather than elipse:<div><br></div>>>> '.'\<br>... .join(<br>...     (<br>...             '1',<br>...             '2',    <br>...     )<br>... )<br>'1.2'<div><br></div><div>This is from Python 2.7.10 (what I have on the machine I am currently on), though I'm fairly sure it has worked for quite a bit longer than that.</div></div><div class="gmail_extra"><br clear="all"><div><div class="gmail_signature" data-smartmail="gmail_signature">Chris</div></div>
<br><div class="gmail_quote">On Wed, Aug 31, 2016 at 2:46 PM, Shane Hathaway <span dir="ltr"><<a href="mailto:shane@hathawaymix.org" target="_blank">shane@hathawaymix.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Hi,<br>
<br>
I write a lot of SQLAlchemy code that looks more or less like this:<br>
<br>
rows = (<br>
    dbsession.query(Table1)<br>
    .join(<br>
        Table2, Table2.y = Table1.y)<br>
    .filter(Table1.x = xx)<br>
    .all())<br>
<br>
The expressions get very long and nearly always need to be spread to multiple lines. I've tried various styles and have chosen the style above as the most tasteful available.<br>
<br>
Pros of the existing syntax:<br>
<br>
- It's possible to indent clearly and consistently.<br>
- Nested indentation works out OK.<br>
- It's flexible; I can combine lines or separate them for emphasis.<br>
<br>
Cons:<br>
<br>
- Extra parentheses are required.<br>
- The indentation is not enforced by the parser, so I have unnecessary freedom that could let various mistakes slip through.<br>
- The closing parenthesis has to move every time I append to or reorder the expression, leading to diff noise in version control. (Alternatively, I could put the closing parenthesis on its own line, but that consumes precious vertical reading space.)<br>
<br>
I'd like to suggest a small change to the Python parser that would make long expressions read better:<br>
<br>
rows = dbsession.query(Table1) ...<br>
    .join(<br>
        Table2, Table2.y = Table1.y)<br>
    .filter(Table1.x = xx)<br>
    .all()<br>
<br>
The idea is to use an ellipsis at the end of a line to spread an expression over multiple indented lines, terminated by a return to an earlier indentation level.  You can still indent more deeply as needed, as shown above by the join() method call.<br>
<br>
This syntax has all the pros of the existing syntax and resolves all the cons:<br>
<br>
- No extra parentheses are required.<br>
- The indentation is enforced, so my mistakes are more likely to be caught early.<br>
- Without a closing parenthesis, there is no diff noise when I append to or reorder an expression.<br>
<br>
I've thought about using a colon instead of an ellipsis, but in Python, a colon starts a list of statements; that's not my goal. Instead, I'm looking for ways to use parser-enforced indentation to avoid mistakes and help my code read better without changing any semantics.<br>
<br>
Feedback is welcome!<br>
<br>
Shane<br>
______________________________<wbr>_________________<br>
Python-ideas mailing list<br>
<a href="mailto:Python-ideas@python.org" target="_blank">Python-ideas@python.org</a><br>
<a href="https://mail.python.org/mailman/listinfo/python-ideas" rel="noreferrer" target="_blank">https://mail.python.org/mailma<wbr>n/listinfo/python-ideas</a><br>
Code of Conduct: <a href="http://python.org/psf/codeofconduct/" rel="noreferrer" target="_blank">http://python.org/psf/codeofco<wbr>nduct/</a><br>
</blockquote></div><br></div>