Speed up inspect.signature() for Python functions
还没有人认领这个 Issue。
- 主要语言
- Python
- 星标
- 77.2k
- 派生
- 35.9k
- PR 合并指标
- PR 指标待抓取
描述
inspect.signature() builds a Signature whose every Parameter is constructed through the public Parameter constructor, which validates the name and kind on each call. When the parameters come from a function's own code object the names are already valid identifiers and the kinds are already the canonical constants, so that validation re-checks facts that are guaranteed to hold.
Signature introspection runs constantly in the ecosystem: web frameworks resolving view and dependency arguments, CLI libraries like click, pytest fixture wiring, and serialization and validation layers all call it per function, often at import time while wiring an application together.
Taking the signature of 400 real callables collected from popular packages (requests, click, jinja2, sqlalchemy, werkzeug, flask and others) takes 1.46 ms today and 1.16 ms when trusted-source parameters skip the redundant validation, 26% faster, with the public Parameter() constructor and its validation unchanged for every other caller.
Linked PRs
- gh-150823
- gh-157463
贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
调研方向
首先跟踪 inspect.signature() 经过 Signature 和公共 Parameter 构造函数的调用流程,重点关注从函数代码对象获取的参数。将现有路径和 Trusted-Source 路径与 issue 中描述的 400-callable 基准进行比较,并验证公共 Parameter() 的验证保持不变,同时复现报告的性能改进。
由索引模型根据 Issue 内容生成。
评估
- 技术栈
- python
- 领域
- developer-experience
- Issue 类型
- 重构
- 难度
- 4/5
- 预计耗时
- 3-5 天
- 活跃度
- 停滞
- 描述清晰度
- 描述清楚
- 新手友好度
- 25/100