warnings.deprecated should support instances as input
Nadie ha tomado este issue todavía.
- Lenguaje dominante
- Python
- Estrellas
- 77.2k
- Forks
- 35.9k
- Métricas de merge de PR
- Métricas de PR pendientes
Descripción
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
Guía de contribución
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Línea de trabajo
Comienza con las líneas 817-833 de Lib/_py_warnings.py, que definen warnings.deprecated, y revisa cómo el decorador gestiona actualmente las entradas de tipo cadena. La tarea se considera completada cuando el decorador también acepta instancias de advertencia, conservando el comportamiento existente; verifica el cambio con las pruebas de advertencias pertinentes.
Escrito por el modelo de indexación a partir del texto del issue.
Evaluación
- Stack tecnológico
- python
- Área
- developer-experience
- Tipo de issue
- Nueva funcionalidad
- Dificultad
- 3/5
- Tiempo estimado
- 1-2 días
- Estado de actividad
- Estancado
- Claridad
- Bastante claro
- Aptitud para principiantes
- 52/100