MCPcopy Create free account
hub / github.com/MagicStack/asyncpg / PyDict_Pop

Function PyDict_Pop

asyncpg/protocol/record/pythoncapi_compat.h:1046–1086  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1044// gh-111262 added PyDict_Pop() and PyDict_PopString() to Python 3.13.0a2
1045#if PY_VERSION_HEX < 0x030D00A2
1046static inline int
1047PyDict_Pop(PyObject *dict, PyObject *key, PyObject **result)
1048{
1049 PyObject *value;
1050
1051 if (!PyDict_Check(dict)) {
1052 PyErr_BadInternalCall();
1053 if (result) {
1054 *result = NULL;
1055 }
1056 return -1;
1057 }
1058
1059 // bpo-16991 added _PyDict_Pop() to Python 3.5.0b2.
1060 // Python 3.6.0b3 changed _PyDict_Pop() first argument type to PyObject*.
1061 // Python 3.13.0a1 removed _PyDict_Pop().
1062#if defined(PYPY_VERSION) || PY_VERSION_HEX < 0x030500b2 || PY_VERSION_HEX >= 0x030D0000
1063 value = PyObject_CallMethod(dict, "pop", "O", key);
1064#elif PY_VERSION_HEX < 0x030600b3
1065 value = _PyDict_Pop(_Py_CAST(PyDictObject*, dict), key, NULL);
1066#else
1067 value = _PyDict_Pop(dict, key, NULL);
1068#endif
1069 if (value == NULL) {
1070 if (result) {
1071 *result = NULL;
1072 }
1073 if (PyErr_Occurred() && !PyErr_ExceptionMatches(PyExc_KeyError)) {
1074 return -1;
1075 }
1076 PyErr_Clear();
1077 return 0;
1078 }
1079 if (result) {
1080 *result = value;
1081 }
1082 else {
1083 Py_DECREF(value);
1084 }
1085 return 1;
1086}
1087
1088static inline int
1089PyDict_PopString(PyObject *dict, const char *key, PyObject **result)

Callers 1

PyDict_PopStringFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected