Skip to content

Commit 8758d54

Browse files
committed
Fix type name shown for t-strings in SyntaxWarnings
1 parent bbcb75c commit 8758d54

File tree

3 files changed

+7
-2
lines changed

3 files changed

+7
-2
lines changed

Lib/test/test_grammar.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1586,6 +1586,7 @@ def check(test):
15861586
check('[[1, 2] [f"{x}"]]')
15871587
check('[[1, 2] [f"x={x}"]]')
15881588
check('[[1, 2] ["abc"]]')
1589+
msg=r'indices must be integers or slices, not string.templatelib.Template;'
15891590
check('[[1, 2] [t"{x}"]]')
15901591
check('[[1, 2] [t"x={x}"]]')
15911592
msg=r'indices must be integers or slices, not'
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Fix type name shown in :exc:`SyntaxWarning`\s involving :ref:`template string
2+
literals <t-strings>`. Patch by Brian Schubert.

Python/codegen.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
#include "pycore_symtable.h" // PySTEntryObject
3030
#include "pycore_unicodeobject.h" // _PyUnicode_EqualToASCIIString
3131
#include "pycore_ceval.h" // SPECIAL___ENTER__
32+
#include "pycore_template.h" // _PyTemplate_Type
3233

3334
#define NEED_OPCODE_METADATA
3435
#include "pycore_opcode_metadata.h" // _PyOpcode_opcode_metadata, _PyOpcode_num_popped/pushed
@@ -3617,10 +3618,11 @@ infer_type(expr_ty e)
36173618
return &PyGen_Type;
36183619
case Lambda_kind:
36193620
return &PyFunction_Type;
3620-
case JoinedStr_kind:
36213621
case TemplateStr_kind:
3622-
case FormattedValue_kind:
36233622
case Interpolation_kind:
3623+
return &_PyTemplate_Type;
3624+
case JoinedStr_kind:
3625+
case FormattedValue_kind:
36243626
return &PyUnicode_Type;
36253627
case Constant_kind:
36263628
return Py_TYPE(e->v.Constant.value);

0 commit comments

Comments
 (0)