python / python/cpython

warnings.deprecated should support instances as input

未關閉
#138,165 0 則留言 0 個 reaction 已指派 0 人 在 GitHub 檢視

還沒有人認領這個 Issue。

stdlib type-feature
主要語言
Python
星號
77.2k
分支
36k
PR 合併指標
PR 指標待擷取

描述

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

貢獻指南

開啟貢獻指南

從這裡開始

  1. 先讀完整個 Issue,再讀專案的貢獻指南。
  2. 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
  3. Fork 儲存庫,在一個分支上完成修改。
  4. 送出 Pull Request,並在描述裡引用這個 Issue 編號。

研究方向

從定義 warnings.deprecated 的 Lib/_py_warnings.py 第 817-833 行開始,檢查裝飾器目前如何處理字串輸入。完成的標準是裝飾器也接受警告實例,同時保留現有行為;使用相關的警告測試驗證這項變更。

由索引模型根據 Issue 內容生成。

評估

技術堆疊
python
領域
developer-experience
Issue 類型
功能
難度
3/5
預估耗時
1-2 天
活躍度
停滯
描述清晰度
基本清楚
新手友好度
52/100

把新 issue 寄到你的電子郵件信箱

精選適合新手參與的 GitHub issue 摘要。