python / python/typing_extensions
Backport support for get_type_hints on lone stringified ClassVar
未关闭
还没有人认领这个 Issue。
- 主要语言
- Python
- 星标
- 583
- 派生
- 146
- 平均合并
- 10 小时 11 分钟
- 30 天内合并 PR
- 5
描述
Currently, both typing.get_type_hints and typing_extensions.get_type_hints fail on a lone stringified ClassVar annotation in Python 3.9 and 3.10:
from __future__ import annotations
from typing import ClassVar, get_type_hints as get_type_hints
from typing_extensions import get_type_hints as get_type_hints_ext
class Foo:
MY_CLASS_CONSTANT: ClassVar = 5
try:
_ = get_type_hints(Foo)
except TypeError as exc:
print(exc)
try:
_ = get_type_hints_ext(Foo)
except TypeError as exc:
print(exc)
This is unfortunate, as https://github.com/python/cpython/issues/90711 addressed this for Python 3.11+, so it would be nice if typing-extensions backported this fix for older python versions.
贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
调研方向
首先在 Python 3.9 和 3.10 上复现所提供的示例,然后检查 typing_extensions.get_type_hints 的实现及其现有测试。当 typing.get_type_hints 和 typing_extensions.get_type_hints 都能像 Python 3.11+ 中那样处理这个唯一的字符串化 ClassVar 时,即表示完成。
由索引模型根据 Issue 内容生成。
评估
- 技术栈
- python
- 领域
- tooling
- Issue 类型
- 缺陷
- 难度
- 3/5
- 预计耗时
- 1-2 天
- 活跃度
- 停滞
- 描述清晰度
- 基本清楚
- 新手友好度
- 45/100