Skip to content

Commit 6c417a8

Browse files
committed
Add PyDict_GetItemWithError
1 parent 76e73e2 commit 6c417a8

2 files changed

Lines changed: 14 additions & 0 deletions

File tree

‎graalpython/com.oracle.graal.python.cext/src/dictobject.c‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,11 @@ PyObject* PyDict_GetItem(PyObject* d, PyObject* k) {
6262
return UPCALL_CEXT_O(_jls_PyDict_GetItem, native_to_java(d), native_to_java(k));
6363
}
6464

65+
UPCALL_ID(PyDict_GetItemWithError);
66+
PyObject* PyDict_GetItemWithError(PyObject* d, PyObject* k) {
67+
return UPCALL_CEXT_O(_jls_PyDict_GetItemWithError, native_to_java(d), native_to_java(k));
68+
}
69+
6570
PyObject* _PyDict_GetItemId(PyObject* d, _Py_Identifier* id) {
6671
return PyDict_GetItemString(d, id->string);
6772
}

‎graalpython/lib-graalpython/python_cext.py‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,15 @@ def PyDict_Copy(dictObj):
162162

163163
@may_raise
164164
def PyDict_GetItem(dictObj, key):
165+
# PyDict_GetItem suppresses all exceptions for historical reasons
166+
try:
167+
return dictObj.get(key, native_null)
168+
except:
169+
return native_null
170+
171+
172+
@may_raise
173+
def PyDict_GetItemWithError(dictObj, key):
165174
if not isinstance(dictObj, dict):
166175
raise TypeError('expected dict, {!s} found'.format(type(dictObj)))
167176
return dictObj.get(key, native_null)

0 commit comments

Comments
 (0)