Making functions/methods subscriptable
还没有人认领这个 Issue。
- 主要语言
- Python
- 星标
- 1.8k
- 派生
- 302
- 平均合并
- 23 小时
- 30 天内合并 PR
- 8
描述
I'd like to make both instances and the types of functions and methods (including builtin methods) subscriptable.
Part of this proposal has been discussed already on python-ideas (https://discuss.python.org/t/making-functions-subscriptable-at-runtime/26463) but I thought it might also be worthwhile making FunctionType etc. subscriptable and work in a similar way to Callable just with extra descriptor behaviour that binds it into a MethodType.
class Foo:
bar: FunctionType[[Self, int], str]
# equivalent to
def bar(self, arg1, /) -> str: ...
This is different from Callable as if FunctionType was replaced with Callable, bar would always require a self argument.
This unfortunately probably requires special casing in type checkers as it isn't quite currently possible with PEP 612 (ParamSpec + Concatenate) (see #946) unless the PEP is updated
贡献指南
这个仓库没有索引到贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
调研方向
先阅读链接的 python-ideas 讨论,然后查看 PEP 612 和 issue #946,以了解所述的限制。该提案涉及可下标的 FunctionType 和相关类型、descriptor 绑定,以及可能需要在 type-checker 中添加特殊处理;要完成这项工作,需要达成一致的设计,并提供相应的 type-checker 支持。
由索引模型根据 Issue 内容生成。
评估
- 技术栈
- python
- 领域
- developer-experience
- Issue 类型
- 功能
- 难度
- 5/5
- 预计耗时
- 一周以上
- 活跃度
- 停滞
- 描述清晰度
- 基本清楚
- 新手友好度
- 25/100