<p dir="ltr">On Aug 31, 2016 7:22 PM, "Chris Kaynor" <<a href="mailto:ckaynor@zindagigames.com">ckaynor@zindagigames.com</a>> wrote:<br>
><br>
> Guido's time machine strikes again, </p>
<p dir="ltr">GAH! We should've just used that for PEPs 484 and 526; instead of trying to prove type hints are useful, Guido could've just:</p>
<p dir="ltr">1. Go 50 years into the future.<br>
2. Make note of the Python's world domination (Perl is overrated).<br>
3. Grab random examples of code using type hints and note that no nuclear missile switches have gone off like last time\b\b\b\b\b\b\b\b\b\b has never happened.<br>
4. Bring them back here and shove it in the rationale.</p>
<p dir="ltr">Problem solved! (Unless of course, the time machine accidentally sets off one of those missile switches like last time\b\b\b\b\b\b\b\b\b\b has never happened.)</p>
<p dir="ltr">> though using a slash (\) rather than elipse:<br>
><br>
> >>> '.'\<br>
> ... .join(<br>
> ...     (<br>
> ...             '1',<br>
> ...             '2',    <br>
> ...     )<br>
> ... )<br>
> '1.2'<br>
><br>
> 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.<br>
><br>
> Chris<br>
><br>
> On Wed, Aug 31, 2016 at 2:46 PM, Shane Hathaway <<a href="mailto:shane@hathawaymix.org">shane@hathawaymix.org</a>> wrote:<br>
>><br>
>> 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>
>> _______________________________________________<br>
>> Python-ideas mailing list<br>
>> <a href="mailto:Python-ideas@python.org">Python-ideas@python.org</a><br>
>> <a href="https://mail.python.org/mailman/listinfo/python-ideas">https://mail.python.org/mailman/listinfo/python-ideas</a><br>
>> Code of Conduct: <a href="http://python.org/psf/codeofconduct/">http://python.org/psf/codeofconduct/</a><br>
><br>
><br>
><br>
> _______________________________________________<br>
> Python-ideas mailing list<br>
> <a href="mailto:Python-ideas@python.org">Python-ideas@python.org</a><br>
> <a href="https://mail.python.org/mailman/listinfo/python-ideas">https://mail.python.org/mailman/listinfo/python-ideas</a><br>
> Code of Conduct: <a href="http://python.org/psf/codeofconduct/">http://python.org/psf/codeofconduct/</a></p>
<p dir="ltr">--<br>
Ryan<br>
[ERROR]: Your autotools build scripts are 200 lines longer than your program. Something’s wrong.<br>
<a href="http://kirbyfan64.github.io/">http://kirbyfan64.github.io/</a></p>