UserString subtypes parameterless `__init__`
未关闭
还没有人认领这个 Issue。
stdlib
type-feature
- 主要语言
- Python
- 星标
- 77.2k
- 派生
- 35.9k
- 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