typing._GenericAlias objects allow arbitrary dunder attribute creation
未关闭
还没有人认领这个 Issue。
stdlib
topic-typing
type-bug
- 主要语言
- Python
- 星标
- 77.2k
- 派生
- 35.9k
- PR 合并指标
- PR 指标待抓取
描述
Bug report
Bug description:
Objects like typing.List[int] allow arbitrary dunders to be set, and because of the cache, those attributes can leak to other objects created elsewhere in the program:
>>> x = List[int]
>>> x.__whatever__ = 42
>>> List[int].__whatever__
42
The cache behavior seems like it could lead to undesirable behavior. In 3.14 we somewhat accidentally fixed a similar bug with Union objects, and it turns out some people were relying on this: #132139. Let's think about whether we also want to remove this wart for other typing objects in 3.15.
CPython versions tested on:
CPython main branch
Operating systems tested on:
No response
贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
调研方向
首先复现 issue 中的 typing.List[int] 示例,并检查 generic aliases 的实现和测试;没有指定文件或测试。首先确定任意 dunder 属性和缓存的 typing 对象应有的行为,然后添加回归测试覆盖,以表明行为是一致的,且属性不会在对象之间泄漏。
由索引模型根据 Issue 内容生成。
评估
- 技术栈
- python
- 领域
- developer-experience
- Issue 类型
- 缺陷
- 难度
- 5/5
- 预计耗时
- 一周以上
- 活跃度
- 停滞
- 描述清晰度
- 需要澄清
- 新手友好度
- 35/100