Open pablogsal opened 3 years ago
Old:
$ ./python -c 'f\'{"x\''
File "<string>", line 1
f'{"x'
^
SyntaxError: f-string: unterminated string
New:
$ ./python -c 'f\'{"x\''
File "<string>", line 1
f'{"x'
^
SyntaxError: unterminated string literal (detected at line 1)
The error seems good, but I wonder if we should still prefix it with f-string:
prefix like previously.
I think it makes sense, I think it should be more or less straightforward because we know if we are in fstring mode.
This is the same in all other errors AFAICT, so I was just thinking of adding the prefix to the error string after parsing, but I am not sure where that code is. That so far has been my biggest problem so far, knowing the code structure and what each bit does :sweat_smile:
so I was just thinking of adding the prefix to the error string after parsing but I am not sure where that code is
For the stuff that is raised at the tokenizer (e.g unterminated string literals), they all should go through this IIRC. https://github.com/we-like-parsers/cpython/blob/435fead4bc7e6a5103bfcfe7ebb67e08ff7dcd04/Parser/tokenizer.c#L1101
For the parser this might help, https://github.com/we-like-parsers/cpython/blob/435fead4bc7e6a5103bfcfe7ebb67e08ff7dcd04/Parser/pegen.c#L366
The error messages in
test_unterminated_string
need updating:There is a bunch of them that need also updating in
test_missing_expression
but we need to check first if we need to change the error we emit in the tokenizer