Open apalala opened 5 years ago
Worth looking at the rules in the reference documentation.
Hi! That’s my jam (though due to dissertation writing priorites not necessarily something I can invest time in for the next 8 months). My arguments why this is a good idea:
r'\'
should be a syntax error, it’s a basically a limitation of abovementioned design that sneaked its way into the grammar.f'Outer! {f"Inner {no_quotes_here}" if p else ""} !'
)Guido seems to be open to this idea, even though he initially said he didn’t want to do this. A recap:
Guido wrote Building a PEG Parser, in which he said:
Tokenizing Python is complicated enough that I don’t want to reimplement it using PEG’s formalism. […] I have no beef with Python’s existing tokenizer, so I want to keep it.
I replied that the different kinds of strings can specifically benefit from an update to the tokenizer (I assume you agreeing with me here is why you created this issue, @apalala :smile:)
Guido replied that Medium is not good for conversation (agreed!) and directed me to discuss.python.org, where I found your thread, which led me here.
FWIW, just because I redirected the conversation doesn’t mean I agree with you. In particular I disagree with points 2 and 3. -- --Guido (mobile)
I didn’t say you’d agreed, just that you seem to be open to discussing it as opposed to shutting it down outright.
But in which way do you disagree with “There’s no reason why r'\'
should be a syntax error”??
It would prevent regular expressions containing quotes. -- --Guido (mobile)
Huh? I’m talking about making raw strings able to end on an odd number of backslashes. I don’t get how that can possibly prevent anything. It’s nothing but the elimination of an inconsistent corner case of the grammar, therefore making Python slightly less surprising.
Well, how would you write a raw string with a quote in it? (Not using the ‘other’ kind of quote.) -- --Guido (mobile)
I’d much prefer being able to do r'\'
and having to use triple quotes for things like r'''^["'\]+$'''
than having an exception built into the grammar just to enable the sequence “backslash-quote” in raw strings. After all, special cases aren't special enough to break the rules :wink:
Had I started coding >11 years ago instead of 10, I’d have had time to argue for getting rid of this behavior in Python 3000, but that ship has sailed I assume.
Let’s agree to disagree. -- --Guido (mobile)
Currently the parser retrieves f-strings as a single lexical element.