[Python-3000] PEP 3125 -- a modest proposal (original) (raw)
Andrew Koenig ark at acm.org
Tue May 8 01:48:27 CEST 2007
- Previous message: [Python-3000] PEP 3129: Class Decorators
- Next message: [Python-3000] PEP 3125 -- a modest proposal
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
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 goes...
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, provided that
Each line after the first is indented strictly more than the firstline (but not necessarily more than the remaining lines in the statement), and
If there is a colon that will precede an indent, it is the lasttoken of the last line, in which case the line after the colon must be indented strictly more than the first line (but not necessarily more than the remaining lines in the statement).
For example:
"abc"
+ "def" # second line with more whitespace than the first --continuation
"abc"
+ "def" # attempt to apply unary + to string literal
"abc"
+ "def"
+ "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 continuationOf course, when "if" isn't followed eventually by a colon, the code won't compile.
However...
x = 3,
4 # x = (3, 4)
x = 3, # x = (3,)
4 # evaluate 4 and throw it awaySo 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...
- Previous message: [Python-3000] PEP 3129: Class Decorators
- Next message: [Python-3000] PEP 3125 -- a modest proposal
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]