warnings.deprecated should support instances as input
Personne n'a encore pris cette issue.
- Langage dominant
- Python
- Étoiles
- 77.2k
- Forks
- 35.9k
- Métriques de merge des PR
- Métriques de PR en attente
Description
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
Guide de contribution
Ouvrir le guide de contribution
Par où commencer
- Lisez l'issue en entier, puis le guide de contribution du projet.
- Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
- Forkez le dépôt et travaillez sur une branche.
- Ouvrez une pull request qui référence le numéro de l'issue.
Piste de recherche
Commencez par les lignes 817-833 de Lib/_py_warnings.py, qui définissent warnings.deprecated, et examinez la manière dont le décorateur traite actuellement les entrées de type chaîne. La tâche est terminée lorsque le décorateur accepte également les instances d’avertissement tout en préservant le comportement existant ; vérifiez la modification avec les tests d’avertissement pertinents.
Rédigé par le modèle d'indexation à partir du texte de l'issue.
Évaluation
- Stack technique
- python
- Domaine
- developer-experience
- Type d'issue
- Fonctionnalité
- Difficulté
- 3/5
- Temps estimé
- 1-2 jours
- Activité
- À l'abandon
- Clarté
- Plutôt claire
- Accessibilité débutants
- 52/100