[Python-ideas] Allow parentheses to be used with "with" block
Martin Teichmann
lkb.teichmann at gmail.com
Mon Feb 16 13:41:23 CET 2015
Hi everyone,
just to toss in my two cents: I would add a completely different way
of line continuation. We could just say "if a line ends in an operator,
it is automatically continued (as if it was in parentheses).
That would allow things like like:
something_long = something_else +
something_more
this would remove the need for many parentheses. It's also not a problem,
as at least until now, a line cannot legally end in an operator (except
when continued).
Well, there is one exception: a line may indeed end in a , (comma).
So I would add another rule: only if a line starts with any of
assert, from, import or with, comma continues a line.
I was thinking about how that could be a problem. A comma at
the end of a line currently means we're creating a tuple. So no
problem with from and import. Also no problem with with, as
it would have to be followed by a colon and a tuples in with
statements also doesn't make much sense. With assert,
this is interestingly already illegal, writing
assert False, 3,
gives a syntax error (why, actually?)
All of what I propose can probably be done in the lexer already.
Those rules sound rather arbitrary, but well, once used I guess
people won't even notice they exist.
Greetings
Martin
More information about the Python-ideas
mailing list