◐ Shell
clean mode source ↗

bpo-40334: Do not show error caret if RAISE_SYNTAX_ERROR_NO_COL_OFFSE… by pablogsal · Pull Request #20020 · python/cpython

I finally solved this mystery, I think.

The reason the old parser doesn't show the caret is because you tried it in the REPL. It seems the old parser doesn't show the source line for errors generated in some later pass (ast.c or the bytecode compiler), because the code that retrieves the source line reads the source file again. Compare these two:

~/cpython$ ./python.exe  -X oldparser
Python 3.9.0a6+ (heads/master:f453221c8b, May 12 2020, 10:45:53) 
[Clang 11.0.0 (clang-1100.0.33.8)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> (pass)
  File "<stdin>", line 1
    (pass)
     ^
SyntaxError: invalid syntax
>>> f() = 1
  File "<stdin>", line 1
SyntaxError: cannot assign to function call
>>> 

Only the first of these shows the source line and the caret, because the error is detected by the (old) parser. The second comes from ast.c and there the attempt to retrieve the source line fails, causing the text member of the SyntaxError object to be None.

But if you put the second syntax error in a file, the old parser shows the source line and the caret (and as I've shown, the caret is in the right place too).

I'm going to close this PR; @lysnikolaou will fix it properly in #20050.