Mark classes as not instantiable
还没有人认领这个 Issue。
评估
调研方向
从 issue 中的运行时示例和链接的 typeshed 参考 python/typeshed#14558 开始。将提议的 new 注解、将 new 设置为 None 以及装饰器与现有的 typing 行为进行比较。完成的标准是,项目已经就如何表达一个类无法被实例化达成一致,并定义了预期的语义。
由索引模型根据 Issue 内容生成。
描述
From python/typeshed#14558: Some classes (like re.Pattern) are not instantiable at runtime:
>>> import re
>>> re.Pattern()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: cannot create 're.Pattern' instances
Currently, there is no working way to mark classes as such. Ideas to mark classes:
- Annotate the return type of
__new__asNoReturn/Never. - Set
__new__toNone(similar to how__hash__works). - A new decorator.
- 主要语言
- Python
- 星标
- 1.8k
- 派生
- 302
- 平均合并
- 23 小时
- 30 天内合并 PR
- 8
贡献指南
这个仓库没有索引到贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
python/typing 的其他 Issue
-
topic: typing spec
难度 2/5 1-3 小时 新手友好度 72/100
-
topic: typing spec
难度 2/5 1-3 小时 新手友好度 75/100
-
topic: documentation
难度 2/5 1-3 小时 新手友好度 76/100
-
topic: documentation
难度 2/5 1-3 小时 新手友好度 65/100
-
topic: conformance tests topic: typing spec
难度 3/5 1-2 天 新手友好度 72/100
相似的 Issue
-
triage/confirmed
难度 2/5 1-3 小时 新手友好度 88/100
agentscope-ai/agentscope#2775 ·
-
comp/desktop P3 type/bug
难度 1/5 1 小时以内 新手友好度 92/100
NousResearch/hermes-agent#118866 ·
-
bug
难度 1/5 1 小时以内 新手友好度 90/100
apache/cloudstack#14222 ·
-
难度 2/5 1-3 小时 新手友好度 76/100
-
bug
难度 2/5 1-3 小时 新手友好度 82/100