spec/conformance: function with TypeVar default and default argument used in context.
未关闭
还没有人认领这个 Issue。
topic: typing spec
- 主要语言
- Python
- 星标
- 1.8k
- 派生
- 302
- 平均合并
- 23 小时
- 30 天内合并 PR
- 8
描述
I want to suggest adding the following test to the conformance test suite:
class Getter[T]:
def get[S=None](self, default: S = None) -> T | S: ... # OK
def test(arg: Getter[str]) -> None:
result: str = arg.get() # type: ignore
- Since the default argument value is assignable to the default type var type,
def getis well-defined arg.get()implicitly usesNoneof typeNoneas the argument. Therefore, we have an implicit constraintS <: Nonewhen.getis called without explicit default.
Therefore, result: str = arg.get() should raise an assignment type error (str | None not assignalbe to str).
Currently, only pyright succeeds on this test, and type checker results diverge.
pyright: no errors (true negative ondef get, true positive onresult) (pyright playground)mypy: false positive ondef get, false negative onresult.ty: false positive ondef get, true positive onresult. (playground)pyrefly: false positive ondef get, false negative onresult(playground)zuban: false postive ondef get, false negative onresult.
Related Issues
- https://github.com/python/mypy/issues/3737 (one of the most upvotes issues on mypy)
- https://github.com/astral-sh/ty/issues/592
贡献指南
这个仓库没有索引到贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
调研方向
首先定位 typing 一致性测试套件,以及其中针对 TypeVar 默认值和默认参数的现有测试。添加所提议的 Getter 示例,并包含预期的定义和赋值诊断,然后比较所列各类型检查器的结果,以明确一致性预期。
由索引模型根据 Issue 内容生成。
评估
- 技术栈
- python
- 领域
- testing
- Issue 类型
- 功能
- 难度
- 3/5
- 预计耗时
- 1-2 天
- 活跃度
- 停滞
- 描述清晰度
- 基本清楚
- 新手友好度
- 42/100