mirror of
https://github.com/python/cpython.git
synced 2025-10-20 08:23:47 +00:00
[3.14] gh-138372: Fix SyntaxWarning for erroneous t-string subscription (GH-138375) (#138392)
gh-138372: Fix SyntaxWarning for erroneous t-string subscription (GH-138375)
(cherry picked from commit 5493b46462
)
Co-authored-by: Brian Schubert <brianm.schubert@gmail.com>
This commit is contained in:
parent
5ec6d56405
commit
192ae9b86d
3 changed files with 12 additions and 7 deletions
|
@ -29,6 +29,7 @@
|
|||
#include "pycore_symtable.h" // PySTEntryObject
|
||||
#include "pycore_unicodeobject.h" // _PyUnicode_EqualToASCIIString
|
||||
#include "pycore_ceval.h" // SPECIAL___ENTER__
|
||||
#include "pycore_template.h" // _PyTemplate_Type
|
||||
|
||||
#define NEED_OPCODE_METADATA
|
||||
#include "pycore_opcode_metadata.h" // _PyOpcode_opcode_metadata, _PyOpcode_num_popped/pushed
|
||||
|
@ -3607,10 +3608,11 @@ infer_type(expr_ty e)
|
|||
return &PyGen_Type;
|
||||
case Lambda_kind:
|
||||
return &PyFunction_Type;
|
||||
case JoinedStr_kind:
|
||||
case TemplateStr_kind:
|
||||
case FormattedValue_kind:
|
||||
case Interpolation_kind:
|
||||
return &_PyTemplate_Type;
|
||||
case JoinedStr_kind:
|
||||
case FormattedValue_kind:
|
||||
return &PyUnicode_Type;
|
||||
case Constant_kind:
|
||||
return Py_TYPE(e->v.Constant.value);
|
||||
|
@ -3664,6 +3666,8 @@ check_subscripter(compiler *c, expr_ty e)
|
|||
case Set_kind:
|
||||
case SetComp_kind:
|
||||
case GeneratorExp_kind:
|
||||
case TemplateStr_kind:
|
||||
case Interpolation_kind:
|
||||
case Lambda_kind: {
|
||||
location loc = LOC(e);
|
||||
return _PyCompile_Warn(c, loc, "'%.200s' object is not subscriptable; "
|
||||
|
@ -3698,9 +3702,7 @@ check_index(compiler *c, expr_ty e, expr_ty s)
|
|||
case List_kind:
|
||||
case ListComp_kind:
|
||||
case JoinedStr_kind:
|
||||
case TemplateStr_kind:
|
||||
case FormattedValue_kind:
|
||||
case Interpolation_kind: {
|
||||
case FormattedValue_kind: {
|
||||
location loc = LOC(e);
|
||||
return _PyCompile_Warn(c, loc, "%.200s indices must be integers "
|
||||
"or slices, not %.200s; "
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue