Cannot assert a callable returns `None` when it must return `None`
还没有人认领这个 Issue。
- 主要语言
- Python
- 星标
- 20.6k
- 派生
- 3.3k
- PR 合并指标
- PR 指标待抓取
描述
Bug Report
mypy prevents you making assertions about callables that must return None when they're called.
This is important as not everyone works in a type-checked context, and so library code must be robust to this.
In my case, I have a chain of callables, the ones in the middle take iterables and return iterables, but the one at the start must take no arguments and the one at the end must consume the upstream iterable and return nothing.
To Reproduce
def returns_none() -> None:
pass
assert returns_none() is None
Expected Behavior
No mypy complaints
Actual Behavior
"returns_none" does not return a value (it only ever returns None) [func-returns-value]
Your Environment
- Mypy version used: mypy 1.10.1 (compiled: yes)
- Mypy command-line flags: none
- Python version used: Python 3.12.1
贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
调研方向
使用所示的 returns_none 函数和断言,在 Python 3.12.1 上通过 mypy 1.10.1 重现该报告。跟踪 func-returns-value 诊断,然后验证对于标注为返回 None 的 callable 的断言不会产生任何提示,同时针对不恰当的值使用,现有诊断仍然保留。
由索引模型根据 Issue 内容生成。
评估
- 技术栈
- python
- 领域
- devtools
- Issue 类型
- 缺陷
- 难度
- 3/5
- 预计耗时
- 1-2 天
- 活跃度
- 停滞
- 描述清晰度
- 基本清楚
- 新手友好度
- 35/100