Async functools.partial calls return an unawaited coroutine
评估
调研方向
从 _CallAndUpdateTrace 开始,其中的协程检查检查的是 partial.__call__ 而不是被包装的函数。使用 issue 中的代码片段复现:它将一个异步的 greet 用 functools.partial 包装,并调用 fire.Fire(..., command=[])。当 partial 返回已 await 的字符串 Rio!、同步 partial 的行为与之前一致,并且回归测试覆盖了两种情况时,即完成。
由索引模型根据 Issue 内容生成。
描述
On current master (716bbc23d7eca949fdb682172283c8d18f742cb6), passing an async function to Fire works, but wrapping it in functools.partial returns the coroutine without running it:
import functools
import inspect
import fire
async def greet(name, suffix="!"):
return name + suffix
result = fire.Fire(functools.partial(greet, "Rio"), command=[])
print(type(result).__name__) # coroutine, rather than str
if inspect.iscoroutine(result):
result.close()
Expected: the command prints Rio! and returns that string. Instead it displays help for the coroutine object and never executes the async function.
_CallAndUpdateTrace inspects partial.__call__, which is not recognized as a coroutine function, rather than the partial itself. Ordinary async callable objects are not affected.
I plan to send a small fix that unwraps the partial only when detecting coroutines, leaving argument parsing unchanged. Regression coverage will include synchronous and asynchronous partials. This does not change event-loop handling or introduce a new async execution mode.
- 主要语言
- Python
- 星标
- 28.2k
- 派生
- 1.5k
- PR 合并指标
- 30 天内没有已合并 PR
环境准备
- 没有 Dockerfile 或 Docker Compose 文件
- 没有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
google/python-fire 的其他 Issue
-
WrappedJoin adds an empty line before an oversized first item可能已有人在做 @GreedyC 于 13 天前认领。 未关闭
难度 2/5 1-3 小时 新手友好度 76/100
google/python-fire#705 ·
-
Brace-based template arguments crash literal parsing with TypeError可能已有人在做 @codewithfourtix 于 13 天前认领。 未关闭
难度 2/5 1-3 小时 新手友好度 76/100
google/python-fire#703 ·
-
Test suite fails on Windows: unescaped path regex in testArgPassing, NamedTemporaryFile reopen in testFileNameFire可能已有人在做 关联的 PR 仍在进行中或已合并。 未关闭
难度 2/5 1-3 小时 新手友好度 85/100
google/python-fire#693 ·
-
Mio ❤️未关闭
难度 5/5 一周以上 新手友好度 1/100
google/python-fire#709 · 2 条评论 ·
-
2083未关闭
难度 5/5 一周以上 新手友好度 5/100
google/python-fire#708 ·
查看 google/python-fire 的全部 Issue
相似的 Issue
-
难度 2/5 1-3 小时 新手友好度 74/100
aws-samples/sample-per-model-bedrock#243 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 66/100
FuRongJun-1999/dsh-memory#404 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 72/100
维护者通常 1 天内回复
-
bug frontend
难度 2/5 1-3 小时 新手友好度 68/100
PennyLaneAI/catalyst#3337 ·
维护者通常 1 天内回复
-
Workflow.schedule stops when a cron deadline passes before sleep可能已有人在做 @HuaTNA 今天认领。 未关闭
难度 2/5 1-3 小时 新手友好度 82/100
维护者通常 1 天内回复