updated for version 7.3.951
Problem: Python exceptions have problems.
Solution: Change some IndexErrors to TypeErrors. Make “line number out of
range” an IndexError. Make “unable to get option value” a
RuntimeError. Make all PyErr_SetString messages start with
lowercase letter and use _(). (ZyX)
diff --git a/src/if_python3.c b/src/if_python3.c
index 8acab9d..02da1b0 100644
--- a/src/if_python3.c
+++ b/src/if_python3.c
@@ -336,6 +336,7 @@
static PyObject *p3imp_PyExc_KeyboardInterrupt;
static PyObject *p3imp_PyExc_TypeError;
static PyObject *p3imp_PyExc_ValueError;
+static PyObject *p3imp_PyExc_RuntimeError;
# define PyExc_AttributeError p3imp_PyExc_AttributeError
# define PyExc_IndexError p3imp_PyExc_IndexError
@@ -343,6 +344,7 @@
# define PyExc_KeyboardInterrupt p3imp_PyExc_KeyboardInterrupt
# define PyExc_TypeError p3imp_PyExc_TypeError
# define PyExc_ValueError p3imp_PyExc_ValueError
+# define PyExc_RuntimeError p3imp_PyExc_RuntimeError
/*
* Table of name to function pointer of python.
@@ -580,12 +582,14 @@
p3imp_PyExc_KeyboardInterrupt = PyDict_GetItemString(exdict, "KeyboardInterrupt");
p3imp_PyExc_TypeError = PyDict_GetItemString(exdict, "TypeError");
p3imp_PyExc_ValueError = PyDict_GetItemString(exdict, "ValueError");
+ p3imp_PyExc_RuntimeError = PyDict_GetItemString(exdict, "RuntimeError");
Py_XINCREF(p3imp_PyExc_AttributeError);
Py_XINCREF(p3imp_PyExc_IndexError);
Py_XINCREF(p3imp_PyExc_KeyError);
Py_XINCREF(p3imp_PyExc_KeyboardInterrupt);
Py_XINCREF(p3imp_PyExc_TypeError);
Py_XINCREF(p3imp_PyExc_ValueError);
+ Py_XINCREF(p3imp_PyExc_RuntimeError);
Py_XDECREF(exmod);
}
#endif /* DYNAMIC_PYTHON3 */
@@ -1132,7 +1136,7 @@
}
else
{
- PyErr_SetString(PyExc_IndexError, "Index must be int or slice");
+ PyErr_SetString(PyExc_TypeError, _("index must be int or slice"));
return NULL;
}
}
@@ -1166,7 +1170,7 @@
}
else
{
- PyErr_SetString(PyExc_IndexError, "Index must be int or slice");
+ PyErr_SetString(PyExc_TypeError, _("index must be int or slice"));
return -1;
}
}
@@ -1248,7 +1252,7 @@
}
else
{
- PyErr_SetString(PyExc_IndexError, "Index must be int or slice");
+ PyErr_SetString(PyExc_TypeError, _("index must be int or slice"));
return NULL;
}
}
@@ -1275,7 +1279,7 @@
}
else
{
- PyErr_SetString(PyExc_IndexError, "Index must be int or slice");
+ PyErr_SetString(PyExc_TypeError, _("index must be int or slice"));
return -1;
}
}
@@ -1450,7 +1454,7 @@
}
else
{
- PyErr_SetString(PyExc_IndexError, "Index must be int or slice");
+ PyErr_SetString(PyExc_TypeError, _("index must be int or slice"));
return NULL;
}
}
@@ -1474,7 +1478,7 @@
}
else
{
- PyErr_SetString(PyExc_IndexError, "Index must be int or slice");
+ PyErr_SetString(PyExc_TypeError, _("index must be int or slice"));
return -1;
}
}