[Python-ideas] Allow parentheses to be used with "with" block

Steven D'Aprano steve at pearwood.info
Mon Feb 16 14:31:59 CET 2015


On Mon, Feb 16, 2015 at 01:41:23PM +0100, Martin Teichmann wrote:
> 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

Implicit line continuations? I think the Zen of Python has something to 
say about explicitness versus implicitness :-)

This would mean that the interpreter would fail to recognise certain 
syntax errors until the next line, or at all:

x = 123 +
mylist.append(None)

currently reports a syntax error in the right place at compile-time:

  x = 123 +
           ^
SyntaxError: invalid syntax


With your suggestion, we wouldn't get a syntax error at all, but a 
runtime TypeError:

TypeError: unsupported operand type(s) for +: 'int' and 'NoneType'


On the other hand, this would give a rather surprising syntax error:

x = 123 +
import math

  import math
       ^
SyntaxError: invalid syntax



-- 
Steven


More information about the Python-ideas mailing list