Skip to content

Commit c12ac29

Browse files
committed
Also fix not-subscriptable case
1 parent 8758d54 commit c12ac29

File tree

3 files changed

+7
-7
lines changed

3 files changed

+7
-7
lines changed

Lib/test/test_grammar.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1554,6 +1554,8 @@ def check(test):
15541554
check('[None [i, j]]')
15551555
check('[True [i, j]]')
15561556
check('[... [i, j]]')
1557+
check('[t"{x}" [i, j]]')
1558+
check('[t"x={x}" [i, j]]')
15571559

15581560
msg=r'indices must be integers or slices, not tuple; perhaps you missed a comma\?'
15591561
check('[(1, 2) [i, j]]')
@@ -1564,8 +1566,6 @@ def check(test):
15641566
check('[f"x={x}" [i, j]]')
15651567
check('["abc" [i, j]]')
15661568
check('[b"abc" [i, j]]')
1567-
check('[t"{x}" [i, j]]')
1568-
check('[t"x={x}" [i, j]]')
15691569

15701570
msg=r'indices must be integers or slices, not tuple;'
15711571
check('[[1, 2] [3, 4]]')
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
Fix type name shown in :exc:`SyntaxWarning`\s involving :ref:`template string
2-
literals <t-strings>`. Patch by Brian Schubert.
1+
Fix :exc:`SyntaxWarning` emitted for erroneous subscript expressions involving
2+
:ref:`template string literals <t-strings>`. Patch by Brian Schubert.

Python/codegen.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3676,6 +3676,8 @@ check_subscripter(compiler *c, expr_ty e)
36763676
case Set_kind:
36773677
case SetComp_kind:
36783678
case GeneratorExp_kind:
3679+
case TemplateStr_kind:
3680+
case Interpolation_kind:
36793681
case Lambda_kind: {
36803682
location loc = LOC(e);
36813683
return _PyCompile_Warn(c, loc, "'%.200s' object is not subscriptable; "
@@ -3710,9 +3712,7 @@ check_index(compiler *c, expr_ty e, expr_ty s)
37103712
case List_kind:
37113713
case ListComp_kind:
37123714
case JoinedStr_kind:
3713-
case TemplateStr_kind:
3714-
case FormattedValue_kind:
3715-
case Interpolation_kind: {
3715+
case FormattedValue_kind: {
37163716
location loc = LOC(e);
37173717
return _PyCompile_Warn(c, loc, "%.200s indices must be integers "
37183718
"or slices, not %.200s; "

0 commit comments

Comments
 (0)