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
分支
36k
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 摘要。