python / python/cpython

warnings.deprecated should support instances as input

Aperta
#138,165 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

stdlib type-feature
Lingua principale
Python
Stelle
77.2k
Fork
35.9k
Metriche di merge delle PR
Metriche PR in attesa

Descrizione

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

Guida per i contributori

Apri la guida per i contributori

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Direzione di ricerca

Inizia dalle righe 817-833 di Lib/_py_warnings.py, che definiscono warnings.deprecated, e verifica come il decoratore gestisce attualmente gli input di tipo stringa. Il completamento richiede che il decoratore accetti anche istanze di warning mantenendo il comportamento esistente; verifica la modifica con i test pertinenti per i warning.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Valutazione

Stack tecnologico
python
Ambito
developer-experience
Tipo di issue
Funzionalità
Difficoltà
3/5
Tempo stimato
1-2 giorni
Stato di attività
Ferma
Chiarezza
Abbastanza chiara
Idoneità per principianti
52/100

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.