+2018-09-16  Tom Tromey  <tom@tromey.com>
+
+       * python/py-threadevent.c (py_get_event_thread): Simplify.
+       * python/py-inferior.c (infpy_thread_from_thread_handle):
+       Return immediately after calling thread_to_thread_object.  Use
+       Py_RETURN_NONE.
+       (thread_to_thread_object): Set the exception on a NULL return.
+
 2018-09-16  Simon Marchi  <simon.marchi@polymtl.ca>
 
        * Makefile.in (LIBGDB_OBS): Sort COMMON_OBS.
 
     if (thread->thread_obj->thread == thr)
       return gdbpy_ref<>::new_reference ((PyObject *) thread->thread_obj);
 
+  PyErr_SetString (PyExc_SystemError,
+                  _("could not find gdb thread object"));
   return NULL;
 }
 
       return NULL;
     }
 
-  gdbpy_ref<> result;
   TRY
     {
       struct thread_info *thread_info;
 
       thread_info = find_thread_by_handle (val, inf_obj->inferior);
       if (thread_info != NULL)
-       result = thread_to_thread_object (thread_info);
+       return thread_to_thread_object (thread_info).release ();
     }
   CATCH (except, RETURN_MASK_ALL)
     {
     }
   END_CATCH
 
-  if (result == NULL)
-    result = gdbpy_ref<>::new_reference (Py_None);
-
-  return result.release ();
+  Py_RETURN_NONE;
 }
 
 /* Implement repr() for gdb.Inferior.  */
 
 gdbpy_ref<>
 py_get_event_thread (ptid_t ptid)
 {
-  gdbpy_ref<> pythread;
-
   if (non_stop)
     {
       thread_info *thread = find_thread_ptid (ptid);
       if (thread != nullptr)
-       pythread = thread_to_thread_object (thread);
-    }
-  else
-    pythread = gdbpy_ref<>::new_reference (Py_None);
-
-  if (pythread == nullptr)
-    {
+       return thread_to_thread_object (thread);
       PyErr_SetString (PyExc_RuntimeError, "Could not find event thread");
       return NULL;
     }
-
-  return pythread;
+  return gdbpy_ref<>::new_reference (Py_None);
 }
 
 gdbpy_ref<>