Move `ContextManager` and `AsyncContextManager` type hinting docs from `typing` to `contextlib`
Ninguém assumiu esta issue ainda.
- Linguagem predominante
- Python
- Estrelas
- 77.2k
- Forks
- 35.9k
- Métricas de merge de PRs
- Métricas de PR pendentes
Descrição
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``.
Guia de contribuição
Primeiros passos
- Leia a issue inteira e depois o guia de contribuição do projeto.
- Comente na issue dizendo que vai assumir — evita que duas pessoas façam o mesmo trabalho.
- Faça um fork do repositório e trabalhe em uma branch.
- Abra um pull request que referencie o número da issue.
Direção de pesquisa
Comece pelas entradas existentes de ContextManager e AsyncContextManager na documentação de contextlib; em seguida, revise a discussão relacionada em #123523 e a documentação de typing vinculada. Adicione as seções de Type hinting solicitadas e os backlinks para os parâmetros genéricos, abrangendo os dois tipos de gerenciador de contexto e seus argumentos de tipo documentados.
Escrita pelo modelo de indexação a partir do texto da issue.
Avaliação
- Stack de tecnologia
- python
- Domínio
- documentation
- Tipo de issue
- Documentação
- Dificuldade
- 2/5
- Tempo estimado
- 1-3 horas
- Status de atividade
- Estagnada
- Clareza
- Claramente especificada
- Facilidade para iniciantes
- 52/100