Skip to content

Commit 14d81dc

Browse files
bpo-42260: Improve error handling in _PyConfig_FromDict (pythonGH-23488)
1 parent c0c23ea commit 14d81dc

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

Python/initconfig.c

+9-4
Original file line numberDiff line numberDiff line change
@@ -1050,8 +1050,8 @@ _PyConfig_AsDict(const PyConfig *config)
10501050
static PyObject*
10511051
config_dict_get(PyObject *dict, const char *name)
10521052
{
1053-
PyObject *item = PyDict_GetItemString(dict, name);
1054-
if (item == NULL) {
1053+
PyObject *item = _PyDict_GetItemStringWithError(dict, name);
1054+
if (item == NULL && !PyErr_Occurred()) {
10551055
PyErr_Format(PyExc_ValueError, "missing config key: %s", name);
10561056
return NULL;
10571057
}
@@ -1085,7 +1085,7 @@ config_dict_get_int(PyObject *dict, const char *name, int *result)
10851085
if (PyErr_ExceptionMatches(PyExc_TypeError)) {
10861086
config_dict_invalid_type(name);
10871087
}
1088-
else {
1088+
else if (PyErr_ExceptionMatches(PyExc_OverflowError)) {
10891089
config_dict_invalid_value(name);
10901090
}
10911091
return -1;
@@ -1104,7 +1104,12 @@ config_dict_get_ulong(PyObject *dict, const char *name, unsigned long *result)
11041104
}
11051105
unsigned long value = PyLong_AsUnsignedLong(item);
11061106
if (value == (unsigned long)-1 && PyErr_Occurred()) {
1107-
config_dict_invalid_value(name);
1107+
if (PyErr_ExceptionMatches(PyExc_TypeError)) {
1108+
config_dict_invalid_type(name);
1109+
}
1110+
else if (PyErr_ExceptionMatches(PyExc_OverflowError)) {
1111+
config_dict_invalid_value(name);
1112+
}
11081113
return -1;
11091114
}
11101115
*result = value;

0 commit comments

Comments
 (0)