mirror of
https://github.com/python/cpython.git
synced 2025-09-26 18:29:57 +00:00
gh-100050: Fix an assertion error when raising unclosed parenthesis errors in the tokenizer (GH-100065)
Automerge-Triggered-By: GH:pablogsal
This commit is contained in:
parent
abbe4482ab
commit
97e7004cfe
3 changed files with 22 additions and 0 deletions
|
@ -2145,6 +2145,22 @@ def func2():
|
||||||
for paren in ")]}":
|
for paren in ")]}":
|
||||||
self._check_error(paren + "1 + 2", f"unmatched '\\{paren}'")
|
self._check_error(paren + "1 + 2", f"unmatched '\\{paren}'")
|
||||||
|
|
||||||
|
# Some more complex examples:
|
||||||
|
code = """\
|
||||||
|
func(
|
||||||
|
a=["unclosed], # Need a quote in this comment: "
|
||||||
|
b=2,
|
||||||
|
)
|
||||||
|
"""
|
||||||
|
self._check_error(code, "parenthesis '\\)' does not match opening parenthesis '\\['")
|
||||||
|
|
||||||
|
def test_error_string_literal(self):
|
||||||
|
|
||||||
|
self._check_error("'blech", "unterminated string literal")
|
||||||
|
self._check_error('"blech', "unterminated string literal")
|
||||||
|
self._check_error("'''blech", "unterminated triple-quoted string literal")
|
||||||
|
self._check_error('"""blech', "unterminated triple-quoted string literal")
|
||||||
|
|
||||||
def test_invisible_characters(self):
|
def test_invisible_characters(self):
|
||||||
self._check_error('print\x17("Hello")', "invalid non-printable character")
|
self._check_error('print\x17("Hello")', "invalid non-printable character")
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,2 @@
|
||||||
|
Honor existing errors obtained when searching for mismatching parentheses in
|
||||||
|
the tokenizer. Patch by Pablo Galindo
|
|
@ -169,6 +169,10 @@ _PyPegen_tokenize_full_source_to_check_for_errors(Parser *p) {
|
||||||
for (;;) {
|
for (;;) {
|
||||||
switch (_PyTokenizer_Get(p->tok, &new_token)) {
|
switch (_PyTokenizer_Get(p->tok, &new_token)) {
|
||||||
case ERRORTOKEN:
|
case ERRORTOKEN:
|
||||||
|
if (PyErr_Occurred()) {
|
||||||
|
ret = -1;
|
||||||
|
goto exit;
|
||||||
|
}
|
||||||
if (p->tok->level != 0) {
|
if (p->tok->level != 0) {
|
||||||
int error_lineno = p->tok->parenlinenostack[p->tok->level-1];
|
int error_lineno = p->tok->parenlinenostack[p->tok->level-1];
|
||||||
if (current_err_line > error_lineno) {
|
if (current_err_line > error_lineno) {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue