[Python-3000] PEP 3125 -- a modest proposal
ark at acm.org
Tue May 8 01:48:27 CEST 2007
Yes, I have read Swift :-) And in that spirit, I don't know whether to take
this proposal seriously because it's kind of radical. Nevertheless, here
It has occurred to me that as Python stands today, an indent always begins
with a colon. So in principle, we could define anything that looks like an
indent but doesn't begin with a colon as a continuation. So the idea would
be that you can continue a statement onto as many lines as you wish,
Each line after the first is indented strictly more than the first
(but not necessarily more than the remaining lines in the
If there is a colon that will precede an indent, it is the last
the last line, in which case the line after the colon must be
strictly more than the first line (but not necessarily more than the
remaining lines in the statement).
+ "def" # second line with more whitespace than the first --
+ "def" # attempt to apply unary + to string literal
+ "ghi" # OK -- this line is indented more than "abc"
This proposal has the advantage of being entirely lexical -- it doesn't even
rely on counting parentheses or brackets, so unlike the current Python rule,
it can be implemented entirely as a regular expression.
It has the disadvantage of being a change, and may have its own pitfalls:
if foo # Oops, I forgot the colon
+ bar # which makes this line a continuation
Of course, when "if" isn't followed eventually by a colon, the code won't
x = 3,
4 # x = (3, 4)
x = 3, # x = (3,)
4 # evaluate 4 and throw it away
So it may be that this proposed rule is too tricky to use. However, it does
have the merit of being even simpler than the current rule.
Just a thought...
More information about the Python-3000