Cache types.GenericAlias in getitems
未关闭
还没有人认领这个 Issue。
performance
stdlib
topic-typing
type-feature
- 主要语言
- Python
- 星标
- 77.2k
- 派生
- 36k
- PR 合并指标
- PR 指标待抓取
描述
The "old-style" generic classes from the typing module (List, Dict, etc) cached typing._GenericAlias instances retuned from __getitem__:
>>> from typing import List
>>> List[int] is List[int]
True
But when this functionality was ported to built-in types, caching was not implemented:
>>> list[int] is list[int]
False
Since it is very common to subscript the same types with the same arguments, caching will be very beneficial here and will reduce memory footprint of heavily type-annotated modules.
Linked PRs
- gh-103541
贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
调研方向
首先检查 typing 模块针对 getitem 的现有缓存行为以及关联的 PR gh-103541。使用 list[int] is list[int] 示例确认预期结果;完成意味着在不改变所述 typing 行为的情况下缓存等价的内置泛型别名。
由索引模型根据 Issue 内容生成。
评估
- 技术栈
- python
- 领域
- backend
- Issue 类型
- 功能
- 难度
- 4/5
- 预计耗时
- 3-5 天
- 活跃度
- 停滞
- 描述清晰度
- 基本清楚
- 新手友好度
- 25/100