TabError and IndentationError from line continuation
未關閉
還沒有人認領這個 Issue。
interpreter-core
topic-parser
type-bug
- 主要語言
- Python
- 星號
- 77.2k
- 分支
- 35.9k
- PR 合併指標
- PR 指標待擷取
描述
Bug report
Bug description:
The documentation states:
Indentation cannot be split over multiple physical lines using backslashes; the whitespace up to the first backslash determines the indentation.
When this rule applies to some, but not all, lines in a block, a TabError is sometimes unexpectedly raised:
L1 = 'if 1:\n'
L2 = ' 1\n'
L3 = ' \\\n'
L4 = ' 1\n'
exec(L1 + L2 + L3 + L4)
# works as expected
L1 = 'if 1:\n'
L2 = '\t1\n'
L3 = '\t\\\n'
L4 = '\t\t1\n'
exec(L1 + L2 + L3 + L4)
# TabError: inconsistent use of tabs and spaces in indentation
Also, when a line containing only a backslash is explicitly joined with an indented line, an IndentationError is unexpectedly raised:
exec('\\\n 1')
# IndentationError: unexpected indent
CPython versions tested on:
3.10, 3.11, 3.12, 3.13, 3.14
Operating systems tested on:
macOS
貢獻指南
從這裡開始
- 先讀完整個 Issue,再讀專案的貢獻指南。
- 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
- Fork 儲存庫,在一個分支上完成修改。
- 送出 Pull Request,並在描述裡引用這個 Issue 編號。
研究方向
先在列出的 CPython 版本上執行兩個 exec() 重現程式,然後追蹤這兩個案例中涉及的縮排與行延續處理。為回報的 TabError 和 IndentationError 行為新增回歸測試覆蓋,並確認測試捕捉到預期結果,同時不變更無關的其他縮排錯誤。
由索引模型根據 Issue 內容生成。
評估
- 技術堆疊
- python
- 領域
- compilers
- Issue 類型
- 缺陷
- 難度
- 4/5
- 預估耗時
- 3-5 天
- 活躍度
- 停滯
- 描述清晰度
- 基本清楚
- 新手友好度
- 38/100