diff --git a/gi/pygobject-object.c b/gi/pygobject-object.c
index b2fe471..b2cfbef 100644
--- a/gi/pygobject-object.c
+++ b/gi/pygobject-object.c
@@ -928,8 +928,11 @@ pygobject_lookup_class(GType gtype)
     if (py_type == NULL) {
 	py_type = g_type_get_qdata(gtype, pyginterface_type_key);
 
-    if (py_type == NULL)
-        py_type = (PyTypeObject *)pygi_type_import_by_g_type(gtype);
+        if (py_type == NULL)
+            py_type = (PyTypeObject *)pygi_type_import_by_g_type(gtype);
+
+        if (PyErr_Occurred())
+            return NULL;
 
 	if (py_type == NULL) {
 	    py_type = pygobject_new_with_interfaces(gtype);
@@ -990,8 +993,11 @@ pygobject_new_full(GObject *obj, gboolean steal, gpointer g_class)
             else
                 tp = pygobject_lookup_class(G_OBJECT_TYPE(obj));
         }
+        if (PyErr_Occurred())
+            return NULL;
+
         g_assert(tp != NULL);
-        
+
         /* need to bump type refcount if created with
            pygobject_new_with_interfaces(). fixes bug #141042 */
         if (tp->tp_flags & Py_TPFLAGS_HEAPTYPE)
