https://gitlab.gnome.org/GNOME/pygobject/-/commit/bfc759c9c0bb

--- gi/gimodule.c.orig	2018-05-31 14:39:04 UTC
+++ gi/gimodule.c
@@ -685,7 +685,10 @@ PYGLIB_MODULE_START(_gi, "_gi")
     pygi_error_register_types (module);
     _pygi_repository_register_types (module);
     _pygi_info_register_types (module);
+    pygobject_type_register_types (module_dict);
+    pygobject_pointer_register_types (module_dict);
     _pygi_struct_register_types (module);
+    pygobject_boxed_register_types (module_dict);
     _pygi_boxed_register_types (module);
     _pygi_ccallback_register_types (module);
     pygi_resulttuple_register_types (module);
@@ -699,12 +702,9 @@ PYGLIB_MODULE_START(_gi, "_gi")
     pygobject_register_features (module_dict);
     pygobject_register_version_tuples (module_dict);
     pygobject_register_warnings (module_dict);
-    pygobject_type_register_types (module_dict);
     pygobject_object_register_types (module_dict);
     pygobject_interface_register_types (module_dict);
     pygobject_paramspec_register_types (module_dict);
-    pygobject_boxed_register_types (module_dict);
-    pygobject_pointer_register_types (module_dict);
     pygobject_enum_register_types (module_dict);
     pygobject_flags_register_types (module_dict);
 
--- gi/pygboxed.c.orig	2018-05-31 14:39:04 UTC
+++ gi/pygboxed.c
@@ -162,6 +162,7 @@ pyg_register_boxed(PyObject *dict, const gchar *class_
     if (!type->tp_dealloc)  type->tp_dealloc  = (destructor)pyg_boxed_dealloc;
 
     Py_TYPE(type) = &PyType_Type;
+    g_assert (Py_TYPE (&PyGBoxed_Type) != NULL);
     type->tp_base = &PyGBoxed_Type;
 
     if (PyType_Ready(type) < 0) {
--- gi/pygi-boxed.c.orig	2018-05-31 14:39:04 UTC
+++ gi/pygi-boxed.c
@@ -230,6 +230,7 @@ void
 _pygi_boxed_register_types (PyObject *m)
 {
     Py_TYPE(&PyGIBoxed_Type) = &PyType_Type;
+    g_assert (Py_TYPE (&PyGBoxed_Type) != NULL);
     PyGIBoxed_Type.tp_base = &PyGBoxed_Type;
     PyGIBoxed_Type.tp_new = (newfunc) _boxed_new;
     PyGIBoxed_Type.tp_init = (initproc) _boxed_init;
--- gi/pygi-struct.c.orig	2018-05-31 14:39:04 UTC
+++ gi/pygi-struct.c
@@ -231,6 +231,7 @@ void
 _pygi_struct_register_types (PyObject *m)
 {
     Py_TYPE(&PyGIStruct_Type) = &PyType_Type;
+    g_assert (Py_TYPE (&PyGPointer_Type) != NULL);
     PyGIStruct_Type.tp_base = &PyGPointer_Type;
     PyGIStruct_Type.tp_new = (newfunc) _struct_new;
     PyGIStruct_Type.tp_init = (initproc) _struct_init;
--- gi/pyginterface.c.orig	2018-05-31 14:39:04 UTC
+++ gi/pyginterface.c
@@ -72,6 +72,7 @@ pyg_register_interface(PyObject *dict, const gchar *cl
     PyObject *o;
 
     Py_TYPE(type) = &PyType_Type;
+    g_assert (Py_TYPE (&PyGInterface_Type) != NULL);
     type->tp_base = &PyGInterface_Type;
 
     if (PyType_Ready(type) < 0) {
--- gi/pygpointer.c.orig	2018-05-31 14:39:04 UTC
+++ gi/pygpointer.c
@@ -117,6 +117,7 @@ pyg_register_pointer(PyObject *dict, const gchar *clas
     if (!type->tp_dealloc) type->tp_dealloc = (destructor)pyg_pointer_dealloc;
 
     Py_TYPE(type) = &PyType_Type;
+    g_assert (Py_TYPE (&PyGPointer_Type) != NULL);
     type->tp_base = &PyGPointer_Type;
 
     if (PyType_Ready(type) < 0) {
--- gi/pygtype.c.orig	2018-05-31 14:39:04 UTC
+++ gi/pygtype.c
@@ -345,6 +345,7 @@ pyg_type_wrapper_new(GType type)
 {
     PyGTypeWrapper *self;
 
+    g_assert (Py_TYPE (&PyGTypeWrapper_Type) != NULL);
     self = (PyGTypeWrapper *)PyObject_NEW(PyGTypeWrapper,
 					  &PyGTypeWrapper_Type);
     if (self == NULL)
