On Nov 14, 2019, at 09:05, Random832 <random832@fastmail.com> wrote:
On Thu, Nov 14, 2019, at 11:54, Paul Moore wrote:
On Thu, 14 Nov 2019 at 16:42, Random832 <random832@fastmail.com> wrote:
So, uh... what if we didn't need backslashes for statements that begin with a keyword and end with a colon? There's no syntactic ambiguity there, right? Honestly, adding this would make me less annoyed with the error I get when I forget the colon, since it'd actually have a purpose other than grit on the screen.
Not sure about ambiguity, but it would require a much more powerful parser than Python currently has (which only looks ahead one token).
Would it? I was thinking it could be the same as parentheses (or inside list/dict/set displays) - it sees the keyword (with, if, for), and now it is in a mode where whitespace does not matter, until it reaches the colon.
Guido is experimenting with PEG parsers, so maybe it will be a possibility in the future, but right now the current parser can't handle it (yes, there are hacks for some special constructs already, but this would need *arbitrary* lookahead - you could have many lines between the with and the colon).
but there's no construct that begins with 'with' and *doesn't* end in a colon.
Yeah, it seems like this should be doable in basically the same way bracketed multiline expressions are. I’m not sure how much of a change that would require. But it seems like it’s worth fiddling with the CPython parser to see if it can actually be done, rather than guessing. That would also let people test that it doesn’t have any unforeseen consequences It would mean free indentation between the first line and the colon, but that’s already true for backslash continuation, and editors and humans manage to make readable code out of that. It might also make error handling a bit worse rather than better. With multiline expressions, what gets dumped with the SyntaxError isn’t always the most relevant part of the expression. (Everyone remembers the first time they left off a close paren and got a baffling error complaining about the perfectly good next line…)