summaryrefslogtreecommitdiffstats
path: root/Modules/_csv.c
diff options
context:
space:
mode:
authorSerhiy Storchaka <storchaka@gmail.com>2024-03-07 09:21:08 (GMT)
committerGitHub <noreply@github.com>2024-03-07 09:21:08 (GMT)
commit72d3cc94cd8cae1925e7a14f297b06ac6184f916 (patch)
treedf9d7a5a97a79f97065282dd8e5a89f57ea2e18b /Modules/_csv.c
parent882fcede83af783a834b759e4643130dc1307ee3 (diff)
downloadcpython-72d3cc94cd8cae1925e7a14f297b06ac6184f916.zip
cpython-72d3cc94cd8cae1925e7a14f297b06ac6184f916.tar.gz
cpython-72d3cc94cd8cae1925e7a14f297b06ac6184f916.tar.bz2
gh-116437: Use new C API PyDict_Pop() to simplify the code (GH-116438)
Diffstat (limited to 'Modules/_csv.c')
-rw-r--r--Modules/_csv.c10
1 files changed, 6 insertions, 4 deletions
diff --git a/Modules/_csv.c b/Modules/_csv.c
index 660c545..ac948f4 100644
--- a/Modules/_csv.c
+++ b/Modules/_csv.c
@@ -1606,10 +1606,12 @@ _csv_unregister_dialect_impl(PyObject *module, PyObject *name)
/*[clinic end generated code: output=0813ebca6c058df4 input=6b5c1557bf60c7e7]*/
{
_csvstate *module_state = get_csv_state(module);
- if (PyDict_DelItem(module_state->dialects, name) < 0) {
- if (PyErr_ExceptionMatches(PyExc_KeyError)) {
- PyErr_Format(module_state->error_obj, "unknown dialect");
- }
+ int rc = PyDict_Pop(module_state->dialects, name, NULL);
+ if (rc < 0) {
+ return NULL;
+ }
+ if (rc == 0) {
+ PyErr_Format(module_state->error_obj, "unknown dialect");
return NULL;
}
Py_RETURN_NONE;