line continuation for lines ending in "and" or "or"

Paul Boddie paul at boddie.org.uk
Thu Jun 5 17:13:07 EDT 2008


On 5 Jun, 22:40, "Terry Reedy" <tjre... at udel.edu> wrote:
>
> A line ending in an operator is ambiguous in that it *could* indicate that
> the programmer intends to continue on the next line while it also could
> indicate that the programmer forgot to finish before hitting return, or
> that something got erased but not replaced.

Yes, this is an excellent point. For the logical operators, consider
code like the following...

  x = obj1.something() and obj2.conditional() and # time for lunch!
  obj4.obligatory_something()

Although a trailing "and" or "or" operator might suggest a
continuation of the expression on the next line, one has to consider
whether the next line (or almost any line defining an expression)
should suggest possible membership of an expression on the preceding
line by default for its contents. One could, of course, insist on
indentation to prevent such ambiguity since the second line above
shouldn't be indented further if part of a separate statement. More
work is definitely needed on such a proposal, certainly.

Paul



More information about the Python-list mailing list