gh-133541: Handle SyntaxError raised by the tokenizer on user input (#133606)

This commit is contained in:
Łukasz Langa 2025-05-08 22:14:38 +02:00 committed by GitHub
parent 6ce469dcba
commit b2fabce6ab
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 24 additions and 0 deletions

View file

@ -102,6 +102,8 @@ def gen_colors(buffer: str) -> Iterator[ColorSpan]:
for color in gen_colors_from_token_stream(gen, line_lengths):
yield color
last_emitted = color
except SyntaxError:
return
except tokenize.TokenError as te:
yield from recover_unterminated_string(
te, line_lengths, last_emitted, buffer