Hacktoberfest 2026:维护者为十月标记出来的 issue,仍然开放、适合新手。 浏览 Hacktoberfest issue

Add async context manager support for AIOHTTPClient and HTTPXClient

未关闭
#1,796 3 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 1 天内回复

还没有人认领这个 Issue。

  • #1806 来自 @jlaportebot —— 已关闭,未合并

评估

难度
3/5
预计耗时
1-2 天
新手友好度
74/100
Issue 类型
功能
描述清晰度
描述清楚
活跃度
活跃
技术栈
python
领域
api, backend

调研方向

阅读 stripe/_http_client.py,并比较 AIOHTTPClient 和 HTTPXClient 上的生命周期方法,尤其是 close() 和 close_async()。为两个支持 async 的客户端添加异步上下文管理器行为,然后验证使用 async with 进入能够正常工作,并且退出时会执行现有的异步清理。

由索引模型根据 Issue 内容生成。

描述

feature-request future
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-op
  • AIOHTTPClient cleanup happens through close_async()
  • HTTPXClient also exposes close_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

环境准备

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

stripe/stripe-python 的其他 Issue

查看 stripe/stripe-python 的全部 Issue

相似的 Issue

更多 Python Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。