UserString subtypes parameterless `__init__`
未關閉
還沒有人認領這個 Issue。
stdlib
type-feature
- 主要語言
- Python
- 星號
- 77.2k
- 分支
- 36k
- PR 合併指標
- PR 指標待擷取
描述
Description
Subtypes of UserString cannot be initialized without a seq argument as the builtin str can.
Reproduction
from collections import UserString
class MyString(UserString):
pass
>>> str()
''
>>> MyString()
Traceback (most recent call last):
File "<python-input-2>", line 1, in <module>
MyString()
~~~~~~~~^^
TypeError: UserString.__init__() missing 1 required positional argument: 'seq'
Workaround
from collections import UserString
class MyString(UserString):
def __init__(self, seq: object = str()) -> None:
super().__init__(seq)
CPython versions tested on:
3.13
Operating systems tested on:
Linux
貢獻指南
從這裡開始
- 先讀完整個 Issue,再讀專案的貢獻指南。
- 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
- Fork 儲存庫,在一個分支上完成修改。
- 送出 Pull Request,並在描述裡引用這個 Issue 編號。
研究方向
從 collections.UserString 入口開始,在 Python 3.13 上重現無參數建構範例。檢查 UserString 的初始化行為,並驗證沒有自訂 init 的子類別可以像 str() 一樣被具現化,同時現有的序列初始化仍然正確。
由索引模型根據 Issue 內容生成。
評估
- 技術堆疊
- python
- 領域
- backend
- Issue 類型
- 缺陷
- 難度
- 2/5
- 預估耗時
- 1-3 小時
- 活躍度
- 停滯
- 描述清晰度
- 基本清楚
- 新手友好度
- 52/100