New asyncio rule: directly passing coroutine to `gather`, `shield`, `wait_for`, `wait`, or `as_completed`
还没有人认领这个 Issue。
评估
调研方向
首先定位现有的 asyncio 规则实现及其测试。跟踪 gather、shield、wait_for、wait 和 as_completed 的直接 coroutine 参数处理,然后验证各个 Python 版本中的预期行为,包括 Python 3.11+ 中的 wait。当新规则能够捕获所描述的直接调用,并且测试覆盖其 false positive 权衡时,即表示完成。
由索引模型根据 Issue 内容生成。
描述
Tasks without saved reference can be garbage collected, and several functions in asyncio automatically converts coroutines into tasks - which means it's ~impossible to save a strong reference to those tasks. See e.g. https://docs.python.org/3/library/asyncio-task.html#asyncio.shield
The rule implementation would be fairly straightforward, just check for calls in the parameter list: asyncio.shield(anything()). This will give false alarms if anything is not a coroutine, but instead a sync function that creates a task, saves it globally, and returns it, but I suspect that's a minority of cases. We could save the names of any sync funcs to reduce the false alarm rate, but that wouldn't work when the functions are imported from other files.
We could also use type-checking to catch
a = my_coro()
asyncio.wait_for(a)
On py311+ asyncio.wait errors if directly passed coroutines.
There appears to be movement in making the event loop save strong references, but that'll probably only affect py3.14/py3.15 or later https://github.com/python/cpython/pull/121264
- 主要语言
- Python
- 星标
- 26
- 派生
- 12
- PR 合并指标
- 30 天内没有已合并 PR
环境准备
- 没有 Dockerfile 或 Docker Compose 文件
- 没有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
python-trio/flake8-async 的其他 Issue
-
rule improvement
难度 2/5 1-3 小时 新手友好度 68/100
python-trio/flake8-async#457 · 1 个 reaction ·
-
Extend ASYNC401 to other forms可能已有人在做 @anshurajbisoyi98-ctrl 于 14 天前认领。 未关闭
难度 3/5 1-2 天 新手友好度 68/100
python-trio/flake8-async#475 · 1 条评论 · 1 个 reaction ·
-
new rule
难度 3/5 1-2 天 新手友好度 55/100
python-trio/flake8-async#454 · 1 条评论 ·
-
rule improvement
难度 3/5 1-2 天 新手友好度 62/100
python-trio/flake8-async#447 · 5 条评论 ·
-
New rule: `ASYNC233` for blocking `pathlib` methods可能已有人在做 @paranoa233 于 102 天前认领。 未关闭good first issue
难度 5/5 一周以上 新手友好度 15/100
python-trio/flake8-async#396 · 1 条评论 ·
查看 python-trio/flake8-async 的全部 Issue
相似的 Issue
-
area: tools documentation good first issue ready for a contributor
难度 2/5 1-3 小时 新手友好度 82/100
eyalgolan/statecraft-israel#873 · 1 条评论 ·
维护者通常 1 天内回复
-
enhancement
难度 2/5 1-3 小时 新手友好度 72/100
维护者通常 5 天内回复
-
bug
难度 2/5 1-3 小时 新手友好度 78/100
维护者通常 1 天内回复
-
bug good first issue
难度 2/5 1-3 小时 新手友好度 85/100
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 72/100
维护者通常 1 天内回复