summaryrefslogtreecommitdiffstats
path: root/Modules/_csv.c
diff options
context:
space:
mode:
authorSerhiy Storchaka <storchaka@gmail.com>2019-02-25 15:59:46 (GMT)
committerGitHub <noreply@github.com>2019-02-25 15:59:46 (GMT)
commita24107b04c1277e3c1105f98aff5bfa3a98b33a0 (patch)
tree55aa5a700e08e3ba27b0361df2b1043be5c4701a /Modules/_csv.c
parenta180b007d96fe68b32f11dec720fbd0cd5b6758a (diff)
downloadcpython-a24107b04c1277e3c1105f98aff5bfa3a98b33a0.zip
cpython-a24107b04c1277e3c1105f98aff5bfa3a98b33a0.tar.gz
cpython-a24107b04c1277e3c1105f98aff5bfa3a98b33a0.tar.bz2
bpo-35459: Use PyDict_GetItemWithError() instead of PyDict_GetItem(). (GH-11112)
Diffstat (limited to 'Modules/_csv.c')
-rw-r--r--Modules/_csv.c10
1 files changed, 7 insertions, 3 deletions
diff --git a/Modules/_csv.c b/Modules/_csv.c
index 6c00974..d86f63e 100644
--- a/Modules/_csv.c
+++ b/Modules/_csv.c
@@ -132,7 +132,7 @@ get_dialect_from_registry(PyObject * name_obj)
{
PyObject *dialect_obj;
- dialect_obj = PyDict_GetItem(_csvstate_global->dialects, name_obj);
+ dialect_obj = PyDict_GetItemWithError(_csvstate_global->dialects, name_obj);
if (dialect_obj == NULL) {
if (!PyErr_Occurred())
PyErr_Format(_csvstate_global->error_obj, "unknown dialect");
@@ -1434,8 +1434,12 @@ csv_register_dialect(PyObject *module, PyObject *args, PyObject *kwargs)
static PyObject *
csv_unregister_dialect(PyObject *module, PyObject *name_obj)
{
- if (PyDict_DelItem(_csvstate_global->dialects, name_obj) < 0)
- return PyErr_Format(_csvstate_global->error_obj, "unknown dialect");
+ if (PyDict_DelItem(_csvstate_global->dialects, name_obj) < 0) {
+ if (PyErr_ExceptionMatches(PyExc_KeyError)) {
+ PyErr_Format(_csvstate_global->error_obj, "unknown dialect");
+ }
+ return NULL;
+ }
Py_RETURN_NONE;
}