Buggy or strange behaviour matching mutable data with `re`
未關閉
還沒有人認領這個 Issue。
extension-modules
topic-regex
type-bug
- 主要語言
- Python
- 星號
- 77.2k
- 分支
- 35.9k
- PR 合併指標
- PR 指標待擷取
描述
Bug report
Bug description:
import re
data = bytearray(b'1')
match = re.match(b'1', data)
print(match[0]) # b'1'
data[:] = b'2'
print(match[0]) # b'2'
If you match against mutable data (e.g., a bytearray) and change that data after matching, the matched values reported by the match change.
Is this a) a bug or b) strange behavior that should be pointed out in the docs (or c) none of the above)?
CPython versions tested on:
3.13
Operating systems tested on:
Linux
貢獻指南
從這裡開始
- 先讀完整個 Issue,再讀專案的貢獻指南。
- 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
- Fork 儲存庫,在一個分支上完成修改。
- 送出 Pull Request,並在描述裡引用這個 Issue 編號。
研究方向
首先,使用可變的 bytearray 執行提供的 Python 3.13 reproducer,並檢查變更後產生的匹配值。閱讀相關的 re 行為和現有測試涵蓋範圍,以判斷這是實作錯誤還是已有文件說明的行為。只有在該行為得到明確解決,並具備相應的回歸測試涵蓋範圍或文件時,才算完成。
由索引模型根據 Issue 內容生成。
評估
- 技術堆疊
- python
- 領域
- backend
- Issue 類型
- 缺陷
- 難度
- 4/5
- 預估耗時
- 3-5 天
- 活躍度
- 停滯
- 描述清晰度
- 基本清楚
- 新手友好度
- 35/100