warnings.deprecated should support instances as input
还没有人认领这个 Issue。
- 主要语言
- Python
- 星标
- 77.2k
- 派生
- 35.9k
- 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
贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
调研方向
从定义 warnings.deprecated 的 Lib/_py_warnings.py 第 817-833 行开始,检查装饰器当前如何处理字符串输入。完成的标准是装饰器也接受警告实例,同时保持现有行为;使用相关的警告测试验证这一更改。
由索引模型根据 Issue 内容生成。
评估
- 技术栈
- python
- 领域
- developer-experience
- Issue 类型
- 功能
- 难度
- 3/5
- 预计耗时
- 1-2 天
- 活跃度
- 停滞
- 描述清晰度
- 基本清楚
- 新手友好度
- 52/100