warnings.deprecated should support instances as input
Ninguém assumiu esta issue ainda.
- Linguagem predominante
- Python
- Estrelas
- 77.2k
- Forks
- 36k
- Métricas de merge de PRs
- Métricas de PR pendentes
Descrição
Feature or enhancement
Proposal:
i'm working on a library that allows to manage the life-cycle of deprecations
its using different warning types based on different contexts and is heavily relying on warnings.warn... supporting passing instances or strings
from deprecator import Deprecator
deprecator = Deprecator.for_package("my_package")
# depending on the version of package and gone_in/warn_in this will be a PendingDeprecation, a Deprecation or a PassedDeprecation as defined in deprecator (Passed deprecations will auto register for triggering errors)
OLD_FEATURE = deprecator.define("Myfeature", warn_in="25.02.0", gone_in="26.05.0", repacement="new feature)
def my_code(...):
warnings.warn(OLD_FEATURE)
i'd like to be able to do
@warnings.deprecated(OLD_FEATURE)
def my_code(...):
...
however currently warnings.deprecated is defined in terms that only allow a string
i'm aware of https://github.com/python/cpython/blob/fd8f42d3d1038a812340c3ec3cbfc995a80c4e13/Lib/_py_warnings.py#L817-L833 and intentional choose a new warning subclass to be registered for errors, as i want to ensure test suites can keep running with records of the issue instead of failures plus enable a work-flow where dead code removal happens after dysfunction sets in so that users have the possibility of a informed workaround while mitigating
Has this already been discussed elsewhere?
This is a minor feature, which does not need previous discussion elsewhere
Links to previous discussion of this feature:
No response
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 linhas 817-833 de Lib/_py_warnings.py, que definem warnings.deprecated, e revise como o decorador lida atualmente com entradas de string. A conclusão ocorre quando o decorador também aceitar instâncias de warning, preservando o comportamento existente; verifique a alteração com os testes relevantes de warning.
Escrita pelo modelo de indexação a partir do texto da issue.
Avaliação
- Stack de tecnologia
- python
- Domínio
- developer-experience
- Tipo de issue
- Funcionalidade
- Dificuldade
- 3/5
- Tempo estimado
- 1-2 dias
- Status de atividade
- Estagnada
- Clareza
- Razoavelmente clara
- Facilidade para iniciantes
- 52/100