GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — `tokenize` crashes on a mismatched closing bracket in an f-string replacement field · Issue #160268 · python/cpython

tokenize crashes on a mismatched closing bracket in an f-string replacement field #160268

New issue
Copy link
New issue
Copy link
Closed
Closed
tokenize crashes on a mismatched closing bracket in an f-string replacement field#160268
Copy link
Labels
interpreter-core(Objects, Python, Grammar, and Parser dirs)(Objects, Python, Grammar, and Parser dirs)topic-parsertype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error

Description

@lysnikolaou
lysnikolaou
opened on Oct 22, 2026
Issue body actions

Bug report

The following snippets crashes with an assertion error on the debug build:

import io, tokenize
list(tokenize.generate_tokens(io.StringIO("f'{]a'").readline))

The ] closes the replacement field's { without an error, because tokenize tolerates mismatched brackets (gh-105042). The f-string state still expects that { on the bracket stack. Release builds don't crash; they read a stale stack entry instead.

The parser rejects the same input with SyntaxError: f-string: unmatched ']', and tokenize mode should do the same.

CPython versions tested on:

CPython main branch

Operating systems tested on:

Linux

Linked PRs

  • gh-160268: Fix tokenize on a mismatched closing bracket in an f-string #160272
  • [3.15] gh-160268: Fix tokenize on a mismatched closing bracket in an f-string (GH-160272) #160335
  • [3.14] gh-160268: Fix tokenize on a mismatched closing bracket in an f-string (GH-160272) #160336

Activity

  1. lysnikolaou
    added
    type-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error
    on Oct 22, 2026
  2. NekoAsakura
    added
    interpreter-core(Objects, Python, Grammar, and Parser dirs)(Objects, Python, Grammar, and Parser dirs)
    topic-parser
    on Oct 22, 2026
  3. johnslavik
    added a commit that references this issue on Oct 22, 2026

    pythongh-160268: Fix tokenize on a mismatched closing bracket in an f…

    86758d1
  4. lysnikolaou
    added 2 commits that reference this issue on Oct 22, 2026

    [3.14] gh-160268: Fix tokenize on a mismatched closing bracket in an …

    25328b3

    [3.15] gh-160268: Fix tokenize on a mismatched closing bracket in an …

    90d0d66
  5. lysnikolaou
    closed this as completedon Oct 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    interpreter-core(Objects, Python, Grammar, and Parser dirs)(Objects, Python, Grammar, and Parser dirs)topic-parsertype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      You are visitor 01402520 — GeezerVison does not store the pages you look up.
      Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.