Skip to content

Commit b81a807

Browse files
committed
Update error messages; add an assert(0)
1 parent 055af82 commit b81a807

File tree

4 files changed

+9
-5
lines changed

4 files changed

+9
-5
lines changed

Grammar/python.gram

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1558,9 +1558,9 @@ invalid_tstring_conversion_character:
15581558

15591559
invalid_string_tstring_concat:
15601560
| a=(fstring|string)+ b[expr_ty]=tstring {
1561-
RAISE_SYNTAX_ERROR_KNOWN_RANGE(PyPegen_last_item(a, expr_ty), b, "cannot mix t-strings with strings or f-strings") }
1561+
RAISE_SYNTAX_ERROR_KNOWN_RANGE(PyPegen_last_item(a, expr_ty), b, "cannot mix t-string literals with string or bytes literals") }
15621562
| a=tstring+ b[expr_ty]=(fstring|string) {
1563-
RAISE_SYNTAX_ERROR_KNOWN_RANGE(PyPegen_last_item(a, expr_ty), b, "cannot mix t-strings with strings or f-strings") }
1563+
RAISE_SYNTAX_ERROR_KNOWN_RANGE(PyPegen_last_item(a, expr_ty), b, "cannot mix t-string literals with string or bytes literals") }
15641564

15651565
invalid_arithmetic:
15661566
| sum ('+'|'-'|'*'|'/'|'%'|'//'|'@') a='not' b=inversion { RAISE_SYNTAX_ERROR_KNOWN_RANGE(a, b, "'not' after an operator must be parenthesized") }

Lib/test/test_tstring.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,7 @@ def test_literal_concatenation(self):
242242

243243
# Test disallowed mix of t-string and string/f-string (incl. bytes)
244244
what = 't'
245-
expected_msg = 'cannot mix t-strings with strings or f-strings'
245+
expected_msg = 'cannot mix t-string literals with string or bytes literals'
246246
for case in (
247247
"t'{what}-string literal' 'str literal'",
248248
"t'{what}-string literal' u'unicode literal'",

Parser/action_helpers.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1871,6 +1871,10 @@ _PyPegen_concatenate_strings(Parser *p, asdl_expr_seq *strings,
18711871
case JoinedStr_kind:
18721872
f_string_found = 1;
18731873
break;
1874+
case TemplateStr_kind:
1875+
// python.gram handles this; we should never get here
1876+
assert(0);
1877+
break;
18741878
default:
18751879
f_string_found = 1;
18761880
break;

Parser/parser.c

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)