Incorrect tests for get_type_hints()
还没有人认领这个 Issue。
- 主要语言
- Python
- 星标
- 77.2k
- 派生
- 35.9k
- PR 合并指标
- PR 指标待抓取
描述
Bug report
Bug description:
A few tests for typing.get_type_hints() test behavior that I feel is incorrect. Fixing it may be more trouble than it's worth, but I thought I'd record these.
- test_get_type_hints_generic
This tests that the a key for the TypedDict is T | None, where T is the TypeVar of that name defined in test_typing.py. However, the relevant TypedDict field is defined in a separate module _typed_dict_helper that has its own T TypeVar. get_type_hints() should pick up the T from the helper module, not the one from test_typing.
This also affects another assertion in the same function.
- test_get_type_hints_classes
This calls get_type_hints() on a class defined like this:
class B(Generic[T]):
class A(Generic[T]):
pass
my_inner_a1: 'B.A'
my_inner_a2: A
my_outer_a: 'A' # unless somebody calls get_type_hints with localns=B.__dict__
It checks that the unquoted A refers to the nested class and the quoted A refers to a different A class in the outer scope. But the fact that the name was quoted shouldn't influence scoping logic; it should resolve to the same name whether or not it's quoted.
I have a change that fixes both of these tests, but I'm not convinced we can afford to change this.
CPython versions tested on:
CPython main branch
Operating systems tested on:
No response
Linked PRs
- gh-137230
贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
调研方向
先从 Lib/test/test_typing.py 中的 test_get_type_hints_generic 和 test_get_type_hints_classes 开始,然后检查 _typed_dict_helper 中引用的定义。在继续之前,运行针对性的 typing 测试并查看链接的 PR gh-137230。完成意味着断言和名称解析预期反映 get_type_hints() 的预期行为,并且相关测试通过。
由索引模型根据 Issue 内容生成。
评估
- 技术栈
- python
- 领域
- testing-qa
- Issue 类型
- 缺陷
- 难度
- 3/5
- 预计耗时
- 1-2 天
- 活跃度
- 停滞
- 描述清晰度
- 基本清楚
- 新手友好度
- 35/100