Add async context manager support for AIOHTTPClient and HTTPXClient
维护者通常 1 天内回复
还没有人认领这个 Issue。
- #1806 来自 @jlaportebot —— 已关闭,未合并
评估
调研方向
阅读 stripe/_http_client.py,并比较 AIOHTTPClient 和 HTTPXClient 上的生命周期方法,尤其是 close() 和 close_async()。为两个支持 async 的客户端添加异步上下文管理器行为,然后验证使用 async with 进入能够正常工作,并且退出时会执行现有的异步清理。
由索引模型根据 Issue 内容生成。
描述
Is your feature request related to a problem? Please describe.
When using the async HTTP clients directly, there is currently no idiomatic way to manage their lifecycle with async with.
In stripe/_http_client.py:
AIOHTTPClient.close()is a no-opAIOHTTPClientcleanup happens throughclose_async()HTTPXClientalso exposesclose_async()- async-capable clients do not appear to expose
__aenter__/__aexit__
That means users need to remember to call close_async() manually instead of using the standard async context-manager pattern.
Describe the solution you'd like
Add async context manager support to async-capable HTTP clients, for example:
async with stripe.AIOHTTPClient() as http_client:
client = stripe.StripeClient("sk_test_...", http_client=http_client)
customer = await client.v1.customers.retrieve_async("cus_123")
Describe alternatives you've considered
Users can call await close_async() manually after using the client, but that is easier to forget and less ergonomic than supporting the standard async with pattern.
Additional context
No response
- 主要语言
- Python
- 星标
- 2.1k
- 派生
- 543
- 平均合并
- 3 天 21 小时
- 30 天内合并 PR
- 15
环境准备
- 没有 Dockerfile 或 Docker Compose 文件
- 有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
stripe/stripe-python 的其他 Issue
-
bug
难度 2/5 1-3 小时 新手友好度 78/100
stripe/stripe-python#1956 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 90/100
stripe/stripe-python#1948 ·
维护者通常 1 天内回复
-
Boolean list elements are encoded as True/False instead of true/false可能重新可做 @inchang-ing 于 7 天前认领,目前没有进行中的 PR。 未关闭bug
难度 2/5 1-3 小时 新手友好度 78/100
stripe/stripe-python#1947 · 3 条评论 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 78/100
stripe/stripe-python#1936 · 2 条评论 ·
维护者通常 1 天内回复
-
难度 3/5 1-2 天 新手友好度 55/100
stripe/stripe-python#1954 · 1 条评论 · 2 个 reaction ·
维护者通常 1 天内回复
查看 stripe/stripe-python 的全部 Issue
相似的 Issue
-
难度 2/5 1-3 小时 新手友好度 78/100
btclib-org/btclib-wallet#587 · 1 条评论 ·
维护者通常 1 天内回复
-
documentation
难度 2/5 1-3 小时 新手友好度 68/100
Judgment-Pack/judgment-pack-spec#275 ·
维护者通常 1 天内回复
-
ai-generated
难度 2/5 1-3 小时 新手友好度 77/100
维护者通常 1 天内回复
-
documentation good first issue priority: low size: XS
难度 1/5 1-3 小时 新手友好度 92/100
yeongseon/azure-functions-doctor-python#651 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 65/100
Changaco/python-libarchive-c#146 ·