configparser.write() loses UNNAMED_SECTION items to DEFAULT on round-trip
未關閉
還沒有人認領這個 Issue。
stdlib
type-bug
- 主要語言
- Python
- 星號
- 77.2k
- 分支
- 36k
- PR 合併指標
- PR 指標待擷取
描述
Bug description
ConfigParser.write() outputs UNNAMED_SECTION items after the [DEFAULT] header. When the output is read back, the headerless items appear under [DEFAULT] and are lost from UNNAMED_SECTION.
import configparser, io
US = configparser.UNNAMED_SECTION
cfg = configparser.ConfigParser(allow_unnamed_section=True)
cfg.read_string('key1 = val1\n[DEFAULT]\ndkey = dval\n[sect1]\nkey2 = val2\n')
out = io.StringIO()
cfg.write(out)
cfg2 = configparser.ConfigParser(allow_unnamed_section=True)
cfg2.read_string(out.getvalue())
print('key1' in cfg2[US]) # False -- lost
print('key1' in cfg2.defaults()) # True -- migrated to DEFAULT
CPython versions tested on
3.14, main
Operating systems tested on
macOS
Linked PRs
- gh-154597
貢獻指南
從這裡開始
- 先讀完整個 Issue,再讀專案的貢獻指南。
- 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
- Fork 儲存庫,在一個分支上完成修改。
- 送出 Pull Request,並在描述裡引用這個 Issue 編號。
研究方向
重現 issue 中展示的往返過程,然後檢查 ConfigParser.write() 和 read_string(),追蹤 UNNAMED_SECTION 中的項目如何被輸出與解析。完成的標準是:寫入並讀取設定後,不帶標頭的鍵仍保留在 cfg2[UNNAMED_SECTION] 中;連結的 PR gh-154597 表示相關工作已經在進行中。
由索引模型根據 Issue 內容生成。
評估
- 技術堆疊
- python
- 領域
- tooling
- Issue 類型
- 缺陷
- 難度
- 2/5
- 預估耗時
- 1-3 小時
- 活躍度
- 停滯
- 描述清晰度
- 描述清楚
- 新手友好度
- 25/100