python / python/cpython

Provide custom error messages for overflows in PyLong_AsLong/PyLong_AsInt()

未关闭
#141,578 2 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

interpreter-core topic-C-API type-feature
主要语言
Python
星标
77.2k
派生
35.9k
PR 合并指标
PR 指标待抓取

描述

Feature or enhancement

Proposal:

Both functions have old TODO comments:
https://github.com/python/cpython/blob/453d886f8592d2f4346d5621b1e4ff31c24338d5/Objects/longobject.c#L671-L676
https://github.com/python/cpython/blob/453d886f8592d2f4346d5621b1e4ff31c24338d5/Objects/longobject.c#L688-L694

Lets either remove these marks or provide different error messages, for example for longs:

if (overflow > 0) {
    PyErr_Format(PyExc_OverflowError,
                 "Python int too large to convert to C long, value > %ld",
                 LONG_MAX);
    return -1;
}
else if (overflow < 0) {
    PyErr_Format(PyExc_OverflowError,
                 "Python int too large to convert to C long, value < %ld",
                 LONG_MIN);
    return -1;
}
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

Linked PRs
  • gh-141585

贡献指南

打开贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

调研方向

从 Objects/longobject.c 中 issue 链接的 TODO 注释开始,并查看链接的 PR gh-141585,了解已经在进行的工作。完成的标准是删除这些 TODO,或者为 PyLong_AsLong() 和 PyLong_AsInt() 提供不同的溢出消息。

由索引模型根据 Issue 内容生成。

评估

技术栈
c, python
领域
api
Issue 类型
功能
难度
3/5
预计耗时
1-2 天
活跃度
停滞
描述清晰度
基本清楚
新手友好度
25/100

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。