python / python/cpython

certain f/t-string expressions not copied correctly to debug str or interpolations

未關閉
#141,271 2 則留言 0 個 reaction 已指派 0 人 在 GitHub 檢視

還沒有人認領這個 Issue。

3.14 3.15 interpreter-core topic-parser type-bug
主要語言
Python
星號
77.2k
分支
35.9k
PR 合併指標
PR 指標待擷取

描述

Bug report

Bug description:

The function set_ftstring_expr() in Parser/lexer/lexer.c does not currently copy certain f/t-string expressions correctly. It has problems with non-coding quotes (escaped or in comments) and nested f/t-strings. This applies to both self-documenting debug expressions and more importantly to t-string interpolation expressions.

For example, the # comment below should not print:

>>> print(f'''{'\'' # comment
... =}''')
'\'' # comment
="'"

Copied expression terminates early:

>>> print(f'{(f'''
... # not comment A
... { # comment B '
... 3 # comment C
... * 2}''', '\n# not comment D\n6')=}')
(f'''
# not comment A
{ # comment B '
3
* 2}''', '\n('\n# not comment A\n6', '\n# not comment D\n6')

It does not appear the function was written to handle nested f/t-strings and the string quote handling does not take into account escaped quotes.

CPython versions tested on:

3.14, CPython main branch

Operating systems tested on:

Linux

Linked PRs
  • gh-141274

貢獻指南

開啟貢獻指南

從這裡開始

  1. 先讀完整個 Issue,再讀專案的貢獻指南。
  2. 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
  3. Fork 儲存庫,在一個分支上完成修改。
  4. 送出 Pull Request,並在描述裡引用這個 Issue 編號。

研究方向

從 Parser/lexer/lexer.c 中的 set_ftstring_expr() 開始,重現報告中逸出的引號、註解和巢狀 f/t-string 範例。追蹤運算式如何為偵錯輸出和 t-string 插值而複製,然後驗證引號括住的文字和註解不會使複製提早終止,並確認所顯示的輸出已修正。

由索引模型根據 Issue 內容生成。

評估

技術堆疊
c
領域
compilers
Issue 類型
缺陷
難度
4/5
預估耗時
3-5 天
活躍度
停滯
描述清晰度
基本清楚
新手友好度
25/100

把新 issue 寄到你的電子郵件信箱

精選適合新手參與的 GitHub issue 摘要。