]> git.ipfire.org Git - thirdparty/Python/cpython.git/commit
bpo-40334: Always show the caret on SyntaxErrors (GH-20050)
authorLysandros Nikolaou <lisandrosnik@gmail.com>
Wed, 13 May 2020 19:36:27 +0000 (22:36 +0300)
committerGitHub <noreply@github.com>
Wed, 13 May 2020 19:36:27 +0000 (20:36 +0100)
commita15c9b3a0524e5ca0434d2ad11076677824af941
treeab2089e87bee11e82d911d3471a8d39192e22139
parentde92769d473d1c0955d36da2fc71462621326f00
bpo-40334: Always show the caret on SyntaxErrors (GH-20050)

This commit fixes SyntaxError locations when the caret is not displayed,
by doing the following:

- `col_number` always gets set to the location of the offending
  node/expr. When no caret is to be displayed, this gets achieved
  by setting the object holding the error line to None.

- Introduce a new function `_PyPegen_raise_error_known_location`,
  which can be called, when an arbitrary `lineno`/`col_offset`
  needs to be passed. This function then gets used in the grammar
  (through some new macros and inline functions) so that SyntaxError
  locations of the new parser match that of the old.
Grammar/python.gram
Lib/test/test_exceptions.py
Parser/pegen/parse.c
Parser/pegen/pegen.c
Parser/pegen/pegen.h