Skip to content

Deduplicate escape/quote scanning in f-string/t-string debug text handling #155516

Open

Description

@ArneshBanerjee

Parser/lexer/string.c has two copies of the same escape-and-quote scanning logic in _PyLexer_set_ftstring_expr (one loop to detect a comment, one to strip it). The two loops drifting apart is what caused gh-154711 / #154914. Follow-up: factor the shared scanning logic into a small helper so the two loops can't diverge again.

Activity

  1. Mystic-W commented on Nov 13, 2026

    @Mystic-W

    It looks like this issue may have been made obsolete by the refactoring in #156484 (part of #153569).

    The original report refers to two duplicated escape/quote scanning loops in _PyLexer_set_ftstring_expr(). However, that function no longer exists on main.

    The current implementation uses finish_ftstring_expr() and _PyLexer_record_ftstring_comment(), with comment spans recorded during tokenization instead of the duplicated scanning logic described here.

    Since the original duplication appears to have been eliminated by that refactoring, would it make sense to close this issue as obsolete?

    Please let me know if I'm missing anything.

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)topic-parsertype-refactorCode refactoring (with no changes in behavior)

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions