`has no attribute "__aiter__"; maybe "__enter__"? (not async iterable)` when async iterating
还没有人认领这个 Issue。
评估
调研方向
首先使用 issue 中的 Python 示例重现诊断结果,并将其与链接的 mypy playground 结果进行比较。跟踪 async-for 错误和建议的处理,然后验证隐式的 aiter 引用不再建议使用 enter;修正后的诊断仍应解释 Foo 不可异步迭代。
由索引模型根据 Issue 内容生成。
描述
Bug Report
On mypy 1.9.0, this code suggests, somewhat nonsensically, __enter__ because __aiter__ does not exist despite the reference to __aiter__ being entirely implicit in the async for loop:
from typing import Self
class Foo:
def __enter__(self) -> Self:
return self
async def f() -> None:
async for x in Foo():
print(x)
On playground: https://mypy-play.net/?mypy=latest&python=3.12&gist=3971471bd809ed97a72a1423a56f5318
Expected Behavior
Since the user did not type __aiter__, it is unlikely that it would be a typo for __enter__; therefore, probably the most helpful course would be to not give that suggestion.
- 主要语言
- Python
- 星标
- 20.6k
- 派生
- 3.3k
- 平均合并
- 1 天 18 小时
- 30 天内合并 PR
- 54
贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
python/mypy 的其他 Issue
-
bug
难度 2/5 1-3 小时 新手友好度 75/100
-
bug
难度 2/5 1-3 小时 新手友好度 78/100
-
bug
难度 2/5 1-3 小时 新手友好度 76/100
-
documentation
难度 2/5 1-3 小时 新手友好度 72/100
-
bug topic-configuration topic-error-reporting
难度 2/5 1-3 小时 新手友好度 68/100
相似的 Issue
-
bug
难度 2/5 1-3 小时 新手友好度 86/100
zostera/django-bootstrap4#894 ·
-
难度 2/5 1-3 小时 新手友好度 78/100
use-agent-os/agent-os#3276 ·
-
难度 2/5 1-3 小时 新手友好度 88/100
zephyrproject-rtos/zephyr#119726 ·
-
area/auth bug comp/agent P3 platform/discord type/security
难度 2/5 1-3 小时 新手友好度 88/100
NousResearch/hermes-agent#117848 ·
-
难度 2/5 1-3 小时 新手友好度 82/100
zilliztech/memsearch#759 ·