Infer descriptor type
还没有人认领这个 Issue。
- 主要语言
- Python
- 星标
- 20.6k
- 派生
- 3.3k
- PR 合并指标
- PR 指标待抓取
描述
Feature
For the common case of a descriptor which behaves like a normal attribute, infer:
class X:
y: int = descriptor()
to:
class X:
y: descriptor[int] = descriptor()
if descriptor is a Generic with one parameter. Extra checks should also be done to make sure that the descriptor is properly typed to behave like an attribute of that type (__get__ and __set__ expect that type on an instance).
Pitch
Type annotations apply to object instances by default, so it's strange to see y: descriptor[int] as type annotation while x.y returns an int.
You could also see a normal attribute as an invisible descriptor whose behavior is to set __dict__[name] (and raise AttributeError on the class), so this could be a way to unify these things.
It's also related to:
https://github.com/python/mypy/issues/7724
https://github.com/python/mypy/issues/5481
I implemented it partially as a plugin but only for my custom descriptors.
贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
调研方向
该 issue 没有指定实现文件、测试或入口点,因此首先查看 issues #7724 和 #5481 中与描述符相关的讨论,以及此处描述的现有 plugin 行为。要视为完成,必须确定推断通用描述符类型并验证其 get 和 set 签名的方法。
由索引模型根据 Issue 内容生成。
评估
- 技术栈
- python
- 领域
- devtools
- Issue 类型
- 功能
- 难度
- 5/5
- 预计耗时
- 一周以上
- 活跃度
- 停滞
- 描述清晰度
- 需要澄清
- 新手友好度
- 25/100