From f4d06d719a258184aeb73d21ef563bb593846c40 Mon Sep 17 00:00:00 2001 From: Michael Droettboom Date: Thu, 5 Nov 2015 14:42:35 -0500 Subject: [PATCH 1/2] SfntNames.get_name() raises KeyError if missing --- docstrings/sfntnames.py | 2 +- src/sfntnames.c | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/docstrings/sfntnames.py b/docstrings/sfntnames.py index 4fab8a4..c6f021e 100644 --- a/docstrings/sfntnames.py +++ b/docstrings/sfntnames.py @@ -42,7 +42,7 @@ This searches the SFNT names to first find a Unicode version of the name, if available, otherwise returning the first found name of the -given type. Returns `None` if no name of the given type was found. +given type. Raises `KeyError` if no name of the given type was found. Parameters ---------- diff --git a/src/sfntnames.c b/src/sfntnames.c index b2ccd57..67e0839 100644 --- a/src/sfntnames.c +++ b/src/sfntnames.c @@ -129,7 +129,8 @@ Py_SfntNames_get_name(Py_SfntNames* self, PyObject* args, PyObject* kwds) { } } - Py_RETURN_NONE; + PyErr_Format(PyExc_KeyError, "No name of type %d", name); + return NULL; }; From 2c80e057a6888dfbb635ca8969d9645e54903310 Mon Sep 17 00:00:00 2001 From: Michael Droettboom Date: Thu, 5 Nov 2015 21:13:10 -0500 Subject: [PATCH 2/2] Simplify. --- src/sfntnames.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/sfntnames.c b/src/sfntnames.c index 67e0839..93f8193 100644 --- a/src/sfntnames.c +++ b/src/sfntnames.c @@ -129,8 +129,7 @@ Py_SfntNames_get_name(Py_SfntNames* self, PyObject* args, PyObject* kwds) { } } - PyErr_Format(PyExc_KeyError, "No name of type %d", name); - return NULL; + return PyErr_Format(PyExc_KeyError, "No name of type %d", name); };