Skip to content

SyntaxWarning for an invalid index type calls a t-string a str #138372

@dscorbett

Description

@dscorbett

Bug report

Bug description:

When a t-string is used as an index, the SyntaxWarning calls it a str. The warning reports the correct type for other types of invalid expression in that context. The TypeError also reports the correct type.

>>> [][t""]
<python-input-0>:1: SyntaxWarning: list indices must be integers or slices, not str; perhaps you missed a comma?
Traceback (most recent call last):
  File "<python-input-0>", line 1, in <module>
    [][t""]
    ~~^^^^^
TypeError: list indices must be integers or slices, not string.templatelib.Template

CPython versions tested on:

3.14

Operating systems tested on:

macOS

Linked PRs

Metadata

Metadata

Assignees

No one assigned

    Labels

    3.14bugs and security fixes3.15new features, bugs and security fixesinterpreter-core(Objects, Python, Grammar, and Parser dirs)type-bugAn unexpected behavior, bug, or error

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions