-
-
Notifications
You must be signed in to change notification settings - Fork 30.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
unterminated string literal tokenization error messages could be better #84357
Comments
It has been pointed out to me that the errors the tokenizer produces for unterminated strings, "EOL while scanning string literal" and "EOF while scanning triple-quoted string literal", contain parsing jargon that make it difficult for new users to understand the problem, likely a missing quote. |
It could be even better. Inside the tokenizer we know where the string literal starts and what quotes it uses. The line and the offset of the *start* of the literal can be set in a SyntaxError. |
Here's my suggestion: End of line reached without finding the end of string literal. Are you missing a closing quote? |
Just re-posting this here from the open PR. Rust's handling of this seems nice and beginner friendly: error: unterminated double quote string Like Serhiy suggested, it points to the /start/ of the string, rather than the EOL and the message seems nice too. |
>>> message = "sadsa
File "<stdin>", line 1
message = "sadsa
^
SyntaxError: unterminated double quote |
I afraid there may be confusion between triple, double and single quoted string literals. So I suggest to change error messages to just "unterminated triple-quoted string literal" and "unterminated string literal" (or "unterminated single-quoted string literal"). Terms "triple-quoted" and "single-quoted" are used several times in the documentation. Term "double-quoted" is used only once, and I suppose in different meaning. |
Fair point. I changed error messages to what you suggested >>> (300) * 6 + ca(e, 2 + "dsadsa)
File "<stdin>", line 1
(300) * 6 + ca(e, 2 + "dsadsa)
^
SyntaxError: unterminated string literal
>>> (300) * 6 + ca(e, 2 + 'dsadsa)
File "<stdin>", line 1
(300) * 6 + ca(e, 2 + 'dsadsa)
^
SyntaxError: unterminated string literal
>>> (300) * 6 + ca(e, 2 + """dsadsa
...
File "<stdin>", line 1
(300) * 6 + ca(e, 2 + """dsadsa
^
SyntaxError: unterminated triple-quoted string literal |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: