◐ Shell
clean mode source ↗

gh-106307: Add PyMapping_GetOptionalItem() by serhiy-storchaka · Pull Request #106308 · python/cpython

Replacement of PyObject_GetItem() which doesn't raise KeyError.

  int _PyMapping_LookupItem(PyObject *obj, PyObject *key, PyObject **result)

Return 1 and set *result != NULL if a key is found.
Return 0 and set *result == NULL if a key is not found;
a KeyError is silenced.
Return -1 and set *result == NULL if an error other than KeyError
is raised.

vstinner

erlend-aasland

@serhiy-storchaka

@serhiy-storchaka serhiy-storchaka changed the title gh-106307: Add _PyMapping_LookupItem() gh-106307: Add PyMapping_GetOptionalItem()

Jul 7, 2023

carljm

vstinner

Co-authored-by: Carl Meyer <carl@oddbird.net>
Co-authored-by: Victor Stinner <vstinner@python.org>
Co-authored-by: Carl Meyer <carl@oddbird.net>

@serhiy-storchaka

vstinner

encukou

@serhiy-storchaka