It is awkward to check whether an obj is of a particular heap type (defined in an extension module)
未關閉
還沒有人認領這個 Issue。
topic-C-API
type-feature
- 主要語言
- Python
- 星號
- 77.2k
- 分支
- 35.9k
- PR 合併指標
- PR 指標待擷取
描述
I wanted to check whether an object is of type array and ended up doing this:
PyObject *exc = PyErr_GetRaisedException();
PyObject *module = PyType_GetModuleByDef(Py_TYPE(lhs), &arraymodule);
if (module == NULL) {
if (!PyErr_Occurred() || PyErr_ExceptionMatches(PyExc_TypeError)) {
/* lhs is not an array instance - ignore the TypeError (if any) */
PyErr_SetRaisedException(exc);
return 0;
}
else {
_PyErr_ChainExceptions1(exc);
return -1;
}
}
PyErr_SetRaisedException(exc);
return array_Check(lhs, get_array_state(module));
CC @ericsnowcurrently @encukou
貢獻指南
從這裡開始
- 先讀完整個 Issue,再讀專案的貢獻指南。
- 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
- Fork 儲存庫,在一個分支上完成修改。
- 送出 Pull Request,並在描述裡引用這個 Issue 編號。
研究方向
從 issue 中展示的 C API 呼叫開始,尤其是 PyType_GetModuleByDef 和 array_Check 範例,以了解目前的型別檢查路徑。檢視相關的 CPython C API 慣例,並確定一種具體且廣泛適用的檢查 heap type 的方式;當就 API 方向達成共識,並具備適當的文件和測試時,即視為完成。
由索引模型根據 Issue 內容生成。
評估
- 技術堆疊
- c, python
- 領域
- api
- Issue 類型
- 功能
- 難度
- 5/5
- 預估耗時
- 一週以上
- 活躍度
- 停滯
- 描述清晰度
- 基本清楚
- 新手友好度
- 35/100