Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Address review
  • Loading branch information
sobolevn committed Apr 30, 2025
commit 40668a51a64c78ccf9fe516747d39093fa86f467
5 changes: 2 additions & 3 deletions Lib/test/test_syntax.py
Original file line number Diff line number Diff line change
Expand Up @@ -1881,18 +1881,17 @@
Traceback (most recent call last):
SyntaxError: can't use 'f' and 't' string prefixes at the same time

>>> x = 1
>>> tf"{x=}"
Traceback (most recent call last):
SyntaxError: can't use 'f' and 't' string prefixes at the same time

>>> tb''
Traceback (most recent call last):
SyntaxError: can't use 't' prefix on bytes
SyntaxError: can't use 'b' and 't' string prefixes at the same time

>>> bt"text"
Traceback (most recent call last):
SyntaxError: can't use 't' prefix on bytes
SyntaxError: can't use 'b' and 't' string prefixes at the same time

>>> t'{x}' = 42
Traceback (most recent call last):
Expand Down
12 changes: 7 additions & 5 deletions Parser/lexer/lexer.c
Original file line number Diff line number Diff line change
Expand Up @@ -672,13 +672,15 @@ tok_get_normal_mode(struct tok_state *tok, tokenizer_mode* current_tok, struct t
c = tok_nextc(tok);
if (c == '"' || c == '\'') {
if (saw_b && saw_t) {
return MAKE_TOKEN(_PyTokenizer_syntaxerror(
tok,
"can't use 't' prefix on bytes"));
return MAKE_TOKEN(_PyTokenizer_syntaxerror_known_range(
tok, (int)(tok->start + 1 - tok->line_start),
(int)(tok->cur - tok->line_start),
"can't use 'b' and 't' string prefixes at the same time"));
}
if (saw_f && saw_t) {
return MAKE_TOKEN(_PyTokenizer_syntaxerror(
tok,
return MAKE_TOKEN(_PyTokenizer_syntaxerror_known_range(
tok, (int)(tok->start + 1 - tok->line_start),
(int)(tok->cur - tok->line_start),
"can't use 'f' and 't' string prefixes at the same time"));
}

Expand Down
Loading