gh-100050: Fix an assertion error when raising unclosed parenthesis errors in the tokenizer (GH-100065)

(cherry picked from commit 97e7004cfe)

Co-authored-by: Pablo Galindo Salgado <Pablogsal@gmail.com>
Automerge-Triggered-By: GH:pablogsal
This commit is contained in:
Miss Islington (bot) 2022-12-07 01:18:00 -08:00 committed by GitHub
parent fbc3e1ed90
commit 2b97ddd512
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 22 additions and 0 deletions

View file

@ -2095,6 +2095,22 @@ def func2():
for paren in ")]}":
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):
self._check_error('print\x17("Hello")', "invalid non-printable character")