Move `ContextManager` and `AsyncContextManager` type hinting docs from `typing` to `contextlib`
还没有人认领这个 Issue。
- 主要语言
- Python
- 星标
- 77.2k
- 派生
- 36k
- PR 合并指标
- PR 指标待抓取
描述
Documentation
PEP585 deprecated typing.ContextManager and typing.AsyncContextManager in favour of their contextlib counterparts. However, contextlib documentation lacks any type hinting information and does not even list generic parameters.
Several relevant changes were discussed along #123523.
Currently there's no backlink from contextlib to typing docs, hence users don't have any trivial way to discover type parameters of ContextManager (that's worse than collections.abc.Generator where such a link exists).
Similarly to #123583, I propose to add a "Type hinting" section to both of them in contextlib documentation:
.. class:: AbstractContextManager
An :term:`abstract base class` for classes that implement
:meth:`object.__enter__` and :meth:`object.__exit__`. A default
implementation for :meth:`object.__enter__` is provided which returns
``self`` while :meth:`object.__exit__` is an abstract method which by default
returns ``None``. See also the definition of :ref:`typecontextmanager`.
:class:`!AbstractContextManager` can be used in type annotations and accepts
two type parameters: ``AbstractContextManager[T_co, ExitT_co]``.
The first type parameter, ``T_co``, represents the type returned by
the :meth:`~object.__enter__` method. The optional second type parameter,
``ExitT_co``, which defaults to ``bool | None``, represents the type
returned by the :meth:`~object.__exit__` method.
.. versionadded:: 3.6
.. versionchanged:: 3.13
Added the optional second type parameter, ``ExitT_co``.
贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
调研方向
先从 contextlib 文档中现有的 ContextManager 和 AsyncContextManager 条目开始,然后查看 #123523 中的相关讨论以及链接的 typing 文档。为泛型参数添加所请求的 Type hinting 部分和反向链接,涵盖两种上下文管理器类型及其文档中记录的类型参数。
由索引模型根据 Issue 内容生成。
评估
- 技术栈
- python
- 领域
- documentation
- Issue 类型
- 文档
- 难度
- 2/5
- 预计耗时
- 1-3 小时
- 活跃度
- 停滞
- 描述清晰度
- 描述清楚
- 新手友好度
- 52/100