[pygobject] Remove gi._gi._gobject and gi._gobject modules



commit b2529624b3925adbef2671025e08cbf747f162e8
Author: Christoph Reiter <creiter src gnome org>
Date:   Mon Mar 27 10:14:22 2017 +0200

    Remove gi._gi._gobject and gi._gobject modules
    
    Expose everything from _gi._gobject in _gi instead.
    This does not move any code around, just removes the module.
    
    Also removes the gi._gobject package and replaces it
    with a small dummy module in gi.__init__.py
    
    https://bugzilla.gnome.org/show_bug.cgi?id=735206

 configure.ac            |    1 -
 gi/Makefile.am          |    3 +-
 gi/__init__.py          |    9 ++++-
 gi/_constants.py        |   52 +++++++++++++++---------------
 gi/_gobject/Makefile.am |   16 ---------
 gi/_gobject/__init__.py |   23 -------------
 gi/_propertyhelper.py   |   47 +++++++++++++--------------
 gi/_signalhelper.py     |    6 ++--
 gi/gimodule.c           |   48 +++++++++++++++++++++------
 gi/gobjectmodule.c      |   82 ++++++++++------------------------------------
 gi/gobjectmodule.h      |   21 ++++++++++++
 gi/module.py            |    6 +--
 gi/overrides/GLib.py    |    3 +-
 gi/overrides/GObject.py |   82 +++++++++++++++++++++++-----------------------
 gi/pygi-value.c         |    2 +-
 gi/pygobject-object.c   |   12 +++---
 gi/types.py             |   13 +++----
 tests/helper.py         |    4 +-
 tests/test_gi.py        |    2 +-
 tests/test_gobject.py   |    8 ++---
 20 files changed, 199 insertions(+), 241 deletions(-)
---
diff --git a/configure.ac b/configure.ac
index b9f1adc..595298b 100644
--- a/configure.ac
+++ b/configure.ac
@@ -211,7 +211,6 @@ AC_CONFIG_FILES(
   gi/Makefile
   gi/repository/Makefile
   gi/overrides/Makefile
-  gi/_gobject/Makefile
   examples/Makefile
   tests/Makefile
   pygtkcompat/Makefile
diff --git a/gi/Makefile.am b/gi/Makefile.am
index 90b6f84..3841075 100644
--- a/gi/Makefile.am
+++ b/gi/Makefile.am
@@ -2,8 +2,7 @@ PLATFORM_VERSION = 3.0
 
 SUBDIRS = \
        repository \
-       overrides \
-       _gobject
+       overrides
 
 extension_cppflags = \
        $(PYTHON_INCLUDES) \
diff --git a/gi/__init__.py b/gi/__init__.py
index 1b139c6..9fefc79 100644
--- a/gi/__init__.py
+++ b/gi/__init__.py
@@ -40,7 +40,6 @@ if 'gobject' in sys.modules:
 
 
 from . import _gi
-from ._gi import _gobject
 from ._gi import _API
 from ._gi import Repository
 from ._gi import PyGIDeprecationWarning
@@ -53,7 +52,13 @@ PyGIWarning = PyGIWarning
 _versions = {}
 _overridesdir = os.path.join(os.path.dirname(__file__), 'overrides')
 
-version_info = _gobject.pygobject_version[:]
+# Needed for compatibility with "pygobject.h"/pygobject_init()
+_gobject = types.ModuleType("gi._gobject")
+sys.modules[_gobject.__name__] = _gobject
+_gobject._PyGObject_API = _gi._PyGObject_API
+_gobject.pygobject_version = _gi.pygobject_version
+
+version_info = _gi.pygobject_version[:]
 __version__ = "{0}.{1}.{2}".format(*version_info)
 
 
diff --git a/gi/_constants.py b/gi/_constants.py
index cec8d17..2153f90 100644
--- a/gi/_constants.py
+++ b/gi/_constants.py
@@ -17,31 +17,31 @@
 # You should have received a copy of the GNU Lesser General Public
 # License along with this library; if not, see <http://www.gnu.org/licenses/>.
 
-from ._gi import _gobject
+from . import _gi
 
-TYPE_INVALID = _gobject.TYPE_INVALID
-TYPE_NONE = _gobject.type_from_name('void')
-TYPE_INTERFACE = _gobject.type_from_name('GInterface')
-TYPE_CHAR = _gobject.type_from_name('gchar')
-TYPE_UCHAR = _gobject.type_from_name('guchar')
-TYPE_BOOLEAN = _gobject.type_from_name('gboolean')
-TYPE_INT = _gobject.type_from_name('gint')
-TYPE_UINT = _gobject.type_from_name('guint')
-TYPE_LONG = _gobject.type_from_name('glong')
-TYPE_ULONG = _gobject.type_from_name('gulong')
-TYPE_INT64 = _gobject.type_from_name('gint64')
-TYPE_UINT64 = _gobject.type_from_name('guint64')
-TYPE_ENUM = _gobject.type_from_name('GEnum')
-TYPE_FLAGS = _gobject.type_from_name('GFlags')
-TYPE_FLOAT = _gobject.type_from_name('gfloat')
-TYPE_DOUBLE = _gobject.type_from_name('gdouble')
-TYPE_STRING = _gobject.type_from_name('gchararray')
-TYPE_POINTER = _gobject.type_from_name('gpointer')
-TYPE_BOXED = _gobject.type_from_name('GBoxed')
-TYPE_PARAM = _gobject.type_from_name('GParam')
-TYPE_OBJECT = _gobject.type_from_name('GObject')
-TYPE_PYOBJECT = _gobject.type_from_name('PyObject')
-TYPE_GTYPE = _gobject.type_from_name('GType')
-TYPE_STRV = _gobject.type_from_name('GStrv')
-TYPE_VARIANT = _gobject.type_from_name('GVariant')
+TYPE_INVALID = _gi.TYPE_INVALID
+TYPE_NONE = _gi.type_from_name('void')
+TYPE_INTERFACE = _gi.type_from_name('GInterface')
+TYPE_CHAR = _gi.type_from_name('gchar')
+TYPE_UCHAR = _gi.type_from_name('guchar')
+TYPE_BOOLEAN = _gi.type_from_name('gboolean')
+TYPE_INT = _gi.type_from_name('gint')
+TYPE_UINT = _gi.type_from_name('guint')
+TYPE_LONG = _gi.type_from_name('glong')
+TYPE_ULONG = _gi.type_from_name('gulong')
+TYPE_INT64 = _gi.type_from_name('gint64')
+TYPE_UINT64 = _gi.type_from_name('guint64')
+TYPE_ENUM = _gi.type_from_name('GEnum')
+TYPE_FLAGS = _gi.type_from_name('GFlags')
+TYPE_FLOAT = _gi.type_from_name('gfloat')
+TYPE_DOUBLE = _gi.type_from_name('gdouble')
+TYPE_STRING = _gi.type_from_name('gchararray')
+TYPE_POINTER = _gi.type_from_name('gpointer')
+TYPE_BOXED = _gi.type_from_name('GBoxed')
+TYPE_PARAM = _gi.type_from_name('GParam')
+TYPE_OBJECT = _gi.type_from_name('GObject')
+TYPE_PYOBJECT = _gi.type_from_name('PyObject')
+TYPE_GTYPE = _gi.type_from_name('GType')
+TYPE_STRV = _gi.type_from_name('GStrv')
+TYPE_VARIANT = _gi.type_from_name('GVariant')
 TYPE_UNICHAR = TYPE_UINT
diff --git a/gi/_propertyhelper.py b/gi/_propertyhelper.py
index 810bdbc..e81de2e 100644
--- a/gi/_propertyhelper.py
+++ b/gi/_propertyhelper.py
@@ -20,8 +20,7 @@
 import sys
 import traceback
 
-import gi._gi
-_gobject = gi._gi._gobject
+from . import _gi
 
 from ._constants import \
     TYPE_NONE, TYPE_INTERFACE, TYPE_CHAR, TYPE_UCHAR, \
@@ -31,14 +30,14 @@ from ._constants import \
     TYPE_POINTER, TYPE_BOXED, TYPE_PARAM, TYPE_OBJECT, \
     TYPE_PYOBJECT, TYPE_GTYPE, TYPE_STRV, TYPE_VARIANT
 
-G_MAXFLOAT = _gobject.G_MAXFLOAT
-G_MAXDOUBLE = _gobject.G_MAXDOUBLE
-G_MININT = _gobject.G_MININT
-G_MAXINT = _gobject.G_MAXINT
-G_MAXUINT = _gobject.G_MAXUINT
-G_MINLONG = _gobject.G_MINLONG
-G_MAXLONG = _gobject.G_MAXLONG
-G_MAXULONG = _gobject.G_MAXULONG
+G_MAXFLOAT = _gi.G_MAXFLOAT
+G_MAXDOUBLE = _gi.G_MAXDOUBLE
+G_MININT = _gi.G_MININT
+G_MAXINT = _gi.G_MAXINT
+G_MAXUINT = _gi.G_MAXUINT
+G_MINLONG = _gi.G_MINLONG
+G_MAXLONG = _gi.G_MAXLONG
+G_MAXULONG = _gi.G_MAXULONG
 
 if sys.version_info >= (3, 0):
     _basestring = str
@@ -153,7 +152,7 @@ class Property(object):
             return "<class 'GObject.Property'>"
 
     def __init__(self, getter=None, setter=None, type=None, default=None,
-                 nick='', blurb='', flags=_gobject.PARAM_READWRITE,
+                 nick='', blurb='', flags=_gi.PARAM_READWRITE,
                  minimum=None, maximum=None):
         self.name = None
 
@@ -211,7 +210,7 @@ class Property(object):
     def __repr__(self):
         return '<GObject Property %s (%s)>' % (
             self.name or '(uninitialized)',
-            _gobject.type_name(self.type))
+            _gi.type_name(self.type))
 
     def __get__(self, instance, klass):
         if instance is None:
@@ -276,11 +275,11 @@ class Property(object):
         if type_ in self._type_from_pytype_lookup:
             return self._type_from_pytype_lookup[type_]
         elif (isinstance(type_, type) and
-              issubclass(type_, (_gobject.GObject,
-                                 _gobject.GEnum,
-                                 _gobject.GFlags,
-                                 _gobject.GBoxed,
-                                 _gobject.GInterface))):
+              issubclass(type_, (_gi.GObject,
+                                 _gi.GEnum,
+                                 _gi.GFlags,
+                                 _gi.GBoxed,
+                                 _gi.GInterface))):
             return type_.__gtype__
         elif type_ in (TYPE_NONE, TYPE_INTERFACE, TYPE_CHAR, TYPE_UCHAR,
                        TYPE_INT, TYPE_UINT, TYPE_BOOLEAN, TYPE_LONG,
@@ -309,24 +308,24 @@ class Property(object):
         elif ptype == TYPE_GTYPE:
             if default is not None:
                 raise TypeError("GType types does not have default values")
-        elif _gobject.type_is_a(ptype, TYPE_ENUM):
+        elif _gi.type_is_a(ptype, TYPE_ENUM):
             if default is None:
                 raise TypeError("enum properties needs a default value")
-            elif not _gobject.type_is_a(default, ptype):
+            elif not _gi.type_is_a(default, ptype):
                 raise TypeError("enum value %s must be an instance of %r" %
                                 (default, ptype))
-        elif _gobject.type_is_a(ptype, TYPE_FLAGS):
-            if not _gobject.type_is_a(default, ptype):
+        elif _gi.type_is_a(ptype, TYPE_FLAGS):
+            if not _gi.type_is_a(default, ptype):
                 raise TypeError("flags value %s must be an instance of %r" %
                                 (default, ptype))
-        elif _gobject.type_is_a(ptype, TYPE_STRV) and default is not None:
+        elif _gi.type_is_a(ptype, TYPE_STRV) and default is not None:
             if not isinstance(default, list):
                 raise TypeError("Strv value %s must be a list" % repr(default))
             for val in default:
                 if type(val) not in (str, bytes):
                     raise TypeError("Strv value %s must contain only strings" % str(default))
-        elif _gobject.type_is_a(ptype, TYPE_VARIANT) and default is not None:
-            if not hasattr(default, '__gtype__') or not _gobject.type_is_a(default, TYPE_VARIANT):
+        elif _gi.type_is_a(ptype, TYPE_VARIANT) and default is not None:
+            if not hasattr(default, '__gtype__') or not _gi.type_is_a(default, TYPE_VARIANT):
                 raise TypeError("variant value %s must be an instance of %r" %
                                 (default, ptype))
 
diff --git a/gi/_signalhelper.py b/gi/_signalhelper.py
index 30ff541..29d36ea 100644
--- a/gi/_signalhelper.py
+++ b/gi/_signalhelper.py
@@ -19,7 +19,7 @@
 
 import sys
 
-from ._gi import _gobject
+from . import _gi
 
 # Callable went away in python 3.0 and came back in 3.2.
 # Use versioning to figure out when to define it, otherwise we have to deal with
@@ -127,7 +127,7 @@ class Signal(str):
             name = name.__name__
         return str.__new__(cls, name)
 
-    def __init__(self, name='', func=None, flags=_gobject.SIGNAL_RUN_FIRST,
+    def __init__(self, name='', func=None, flags=_gi.SIGNAL_RUN_FIRST,
                  return_type=None, arg_types=None, doc='', accumulator=None, accu_data=None):
         if func and not name:
             name = func.__name__
@@ -164,7 +164,7 @@ class Signal(str):
 
         # If obj is a GObject, than we call this signal as a closure otherwise
         # it is used as a re-application of a decorator.
-        if isinstance(obj, _gobject.GObject):
+        if isinstance(obj, _gi.GObject):
             self.func(obj, *args, **kargs)
         else:
             # If self is already an allocated name, use it otherwise create a new named
diff --git a/gi/gimodule.c b/gi/gimodule.c
index 69fa013..e14b4f6 100644
--- a/gi/gimodule.c
+++ b/gi/gimodule.c
@@ -43,9 +43,13 @@
 #include "pygi-boxed.h"
 #include "pygi-info.h"
 #include "pygi-struct.h"
+#include "pygobject-object.h"
 #include "pygoptioncontext.h"
 #include "pygoptiongroup.h"
 #include "pygspawn.h"
+#include "gobjectmodule.h"
+#include "pygparamspec.h"
+#include "pygpointer.h"
 
 #include <pyglib-python-compat.h>
 
@@ -641,6 +645,25 @@ static PyMethodDef _gi_functions[] = {
       "\n"
       "Execute a child program asynchronously within a glib.MainLoop()\n"
       "See the reference manual for a complete reference.\n" },
+    { "type_name", pyg_type_name, METH_VARARGS },
+    { "type_from_name", pyg_type_from_name, METH_VARARGS },
+    { "type_is_a", pyg_type_is_a, METH_VARARGS },
+    { "type_register", _wrap_pyg_type_register, METH_VARARGS },
+    { "signal_new", pyg_signal_new, METH_VARARGS },
+    { "list_properties",
+      pyg_object_class_list_properties, METH_VARARGS },
+    { "new",
+      (PyCFunction)pyg_object_new, METH_VARARGS|METH_KEYWORDS },
+    { "signal_accumulator_true_handled",
+      (PyCFunction)pyg_signal_accumulator_true_handled, METH_VARARGS },
+    { "add_emission_hook",
+      (PyCFunction)pyg_add_emission_hook, METH_VARARGS },
+    { "_install_metaclass",
+      (PyCFunction)pyg__install_metaclass, METH_O },
+    { "_gvalue_get",
+      (PyCFunction)pyg__gvalue_get, METH_O },
+    { "_gvalue_set",
+      (PyCFunction)pyg__gvalue_set, METH_VARARGS },
     { NULL, NULL, 0 }
 };
 
@@ -651,7 +674,6 @@ static struct PyGI_API CAPI = {
 PYGLIB_MODULE_START(_gi, "_gi")
 {
     PyObject *api;
-    PyObject *_gobject_module;
     PyObject *module_dict = PyModule_GetDict (module);
 
     /* Always enable Python threads since we cannot predict which GI repositories
@@ -663,16 +685,6 @@ PYGLIB_MODULE_START(_gi, "_gi")
 
     PyModule_AddStringConstant(module, "__package__", "gi._gi");
 
-    _gobject_module = pyglib__gobject_module_create ();
-    if (_gobject_module == NULL) {
-        return PYGLIB_MODULE_ERROR_RETURN;
-    }
-    if (PY_MAJOR_VERSION < 3) {
-        Py_INCREF (_gobject_module);
-    }
-    PyModule_AddObject (module, "_gobject", _gobject_module);
-    PyModule_AddStringConstant(module, "__package__", "gi._gi");
-
     pygi_foreign_init ();
     pygi_error_register_types (module);
     _pygi_repository_register_types (module);
@@ -686,6 +698,20 @@ PYGLIB_MODULE_START(_gi, "_gi")
     pyglib_option_context_register_types (module_dict);
     pyglib_option_group_register_types (module_dict);
 
+    pygobject_register_api (module_dict);
+    pygobject_register_constants (module);
+    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);
+
     PyGIWarning = PyErr_NewException ("gi.PyGIWarning", PyExc_Warning, NULL);
 
     /* Use RuntimeWarning as the base class of PyGIDeprecationWarning
diff --git a/gi/gobjectmodule.c b/gi/gobjectmodule.c
index 0f3448e..ba1b9fc 100644
--- a/gi/gobjectmodule.c
+++ b/gi/gobjectmodule.c
@@ -88,7 +88,7 @@ pyg_destroy_notify(gpointer user_data)
 
 /* ---------------- gobject module functions -------------------- */
 
-static PyObject *
+PyObject *
 pyg_type_name (PyObject *self, PyObject *args)
 {
     PyObject *gtype;
@@ -113,7 +113,7 @@ pyg_type_name (PyObject *self, PyObject *args)
     return NULL;
 }
 
-static PyObject *
+PyObject *
 pyg_type_from_name (PyObject *self, PyObject *args)
 {
     const gchar *name;
@@ -138,7 +138,7 @@ pyg_type_from_name (PyObject *self, PyObject *args)
     return NULL;
 }
 
-static PyObject *
+PyObject *
 pyg_type_is_a (PyObject *self, PyObject *args)
 {
     PyObject *gtype, *gparent;
@@ -892,7 +892,7 @@ pyg_run_class_init(GType gtype, gpointer gclass, PyTypeObject *pyclass)
     return 0;
 }
 
-static PyObject *
+PyObject *
 _wrap_pyg_type_register(PyObject *self, PyObject *args)
 {
     PyTypeObject *class;
@@ -1215,7 +1215,7 @@ pyg_type_register(PyTypeObject *class, const char *type_name)
     return 0;
 }
 
-static PyObject *
+PyObject *
 pyg_signal_new(PyObject *self, PyObject *args)
 {
     gchar *signal_name;
@@ -1282,7 +1282,7 @@ pyg_signal_new(PyObject *self, PyObject *args)
     return NULL;
 }
 
-static PyObject *
+PyObject *
 pyg_object_class_list_properties (PyObject *self, PyObject *args)
 {
     GParamSpec **specs;
@@ -1339,7 +1339,7 @@ pyg_object_class_list_properties (PyObject *self, PyObject *args)
     return list;
 }
 
-static PyObject *
+PyObject *
 pyg_object_new (PyGObject *self, PyObject *args, PyObject *kwargs)
 {
     PyObject *pytype;
@@ -1415,7 +1415,7 @@ pygobject_enable_threads(void)
     return 0;
 }
 
-static PyObject *
+PyObject *
 pyg_signal_accumulator_true_handled(PyObject *unused, PyObject *args)
 {
     PyErr_SetString(PyExc_TypeError,
@@ -1472,7 +1472,7 @@ out:
     return retval;
 }
 
-static PyObject *
+PyObject *
 pyg_add_emission_hook(PyGObject *self, PyObject *args)
 {
     PyObject *first, *callback, *extra_args, *data, *repr;
@@ -1530,7 +1530,7 @@ pyg_add_emission_hook(PyGObject *self, PyObject *args)
     return PyLong_FromUnsignedLong(hook_id);
 }
 
-static PyObject *
+PyObject *
 pyg__install_metaclass(PyObject *dummy, PyTypeObject *metaclass)
 {
     Py_INCREF(metaclass);
@@ -1543,7 +1543,7 @@ pyg__install_metaclass(PyObject *dummy, PyTypeObject *metaclass)
     return Py_None;
 }
 
-static PyObject *
+PyObject *
 pyg__gvalue_get(PyObject *module, PyObject *pygvalue)
 {
     if (!pyg_boxed_check (pygvalue, G_TYPE_VALUE)) {
@@ -1555,13 +1555,13 @@ pyg__gvalue_get(PyObject *module, PyObject *pygvalue)
                                   /*copy_boxed=*/ TRUE);
 }
 
-static PyObject *
+PyObject *
 pyg__gvalue_set(PyObject *module, PyObject *args)
 {
     PyObject *pygvalue;
     PyObject *pyobject;
 
-    if (!PyArg_ParseTuple (args, "OO:_gobject._gvalue_set",
+    if (!PyArg_ParseTuple (args, "OO:_gi._gvalue_set",
                            &pygvalue, &pyobject))
         return NULL;
 
@@ -1577,30 +1577,6 @@ pyg__gvalue_set(PyObject *module, PyObject *args)
     Py_RETURN_NONE;
 }
 
-static PyMethodDef _gobject_functions[] = {
-    { "type_name", pyg_type_name, METH_VARARGS },
-    { "type_from_name", pyg_type_from_name, METH_VARARGS },
-    { "type_is_a", pyg_type_is_a, METH_VARARGS },
-    { "type_register", _wrap_pyg_type_register, METH_VARARGS },
-    { "signal_new", pyg_signal_new, METH_VARARGS },
-    { "list_properties",
-      pyg_object_class_list_properties, METH_VARARGS },
-    { "new",
-      (PyCFunction)pyg_object_new, METH_VARARGS|METH_KEYWORDS },
-    { "signal_accumulator_true_handled",
-      (PyCFunction)pyg_signal_accumulator_true_handled, METH_VARARGS },
-    { "add_emission_hook",
-      (PyCFunction)pyg_add_emission_hook, METH_VARARGS },
-    { "_install_metaclass",
-      (PyCFunction)pyg__install_metaclass, METH_O },
-    { "_gvalue_get",
-      (PyCFunction)pyg__gvalue_get, METH_O },
-    { "_gvalue_set",
-      (PyCFunction)pyg__gvalue_set, METH_VARARGS },
-
-    { NULL, NULL, 0 }
-};
-
 
 /* ----------------- Constant extraction ------------------------ */
 
@@ -1924,7 +1900,7 @@ struct _PyGObject_Functions pygobject_api_functions = {
 };
 
 /* for addon libraries ... */
-static void
+void
 pygobject_register_api(PyObject *d)
 {
     PyObject *api;
@@ -1935,7 +1911,7 @@ pygobject_register_api(PyObject *d)
 }
 
 /* some constants */
-static void
+void
 pygobject_register_constants(PyObject *m)
 {
     /* PyFloat_ return a new ref, and add object takes the ref */
@@ -1967,7 +1943,7 @@ pygobject_register_constants(PyObject *m)
 }
 
 /* features */
-static void
+void
 pygobject_register_features(PyObject *d)
 {
     PyObject *features;
@@ -1978,7 +1954,7 @@ pygobject_register_features(PyObject *d)
     Py_DECREF(features);
 }
 
-static void
+void
 pygobject_register_version_tuples(PyObject *d)
 {
     PyObject *tuple;
@@ -1991,7 +1967,7 @@ pygobject_register_version_tuples(PyObject *d)
     PyDict_SetItemString(d, "pygobject_version", tuple);
 }
 
-static void
+void
 pygobject_register_warnings(PyObject *d)
 {
     PyObject *warning;
@@ -2002,25 +1978,3 @@ pygobject_register_warnings(PyObject *d)
     add_warning_redirection("GLib-GObject", warning);
     add_warning_redirection("GThread", warning);
 }
-
-
-PYGLIB_MODULE_START(_gobject, "_gobject")
-{
-    PyObject *d;
-
-    d = PyModule_GetDict(module);
-    pygobject_register_api(d);
-    pygobject_register_constants(module);
-    pygobject_register_features(d);
-    pygobject_register_version_tuples(d);
-    pygobject_register_warnings(d);
-    pygobject_type_register_types(d);
-    pygobject_object_register_types(d);
-    pygobject_interface_register_types(d);
-    pygobject_paramspec_register_types(d);
-    pygobject_boxed_register_types(d);
-    pygobject_pointer_register_types(d);
-    pygobject_enum_register_types(d);
-    pygobject_flags_register_types(d);
-}
-PYGLIB_MODULE_END
diff --git a/gi/gobjectmodule.h b/gi/gobjectmodule.h
index 11f99cf..50bb6d1 100644
--- a/gi/gobjectmodule.h
+++ b/gi/gobjectmodule.h
@@ -8,4 +8,25 @@ int           pygobject_constructv (PyGObject   *self,
                                     guint        n_parameters,
                                     GParameter  *parameters);
 
+void        pygobject_register_api              (PyObject *d);
+void        pygobject_register_constants        (PyObject *m);
+void        pygobject_register_features         (PyObject *d);
+void        pygobject_register_version_tuples   (PyObject *d);
+void        pygobject_register_warnings         (PyObject *d);
+
+PyObject *  pyg_type_name                       (PyObject *self, PyObject *args);
+PyObject *  pyg_type_from_name                  (PyObject *self, PyObject *args);
+PyObject *  pyg_type_is_a                       (PyObject *self, PyObject *args);
+PyObject *  _wrap_pyg_type_register             (PyObject *self, PyObject *args);
+PyObject *  pyg_signal_new                      (PyObject *self, PyObject *args);
+PyObject *  pyg_object_class_list_properties    (PyObject *self, PyObject *args);
+PyObject *  pyg_object_new                      (PyGObject *self, PyObject *args,
+                                                 PyObject *kwargs);
+PyObject *  pyg_signal_accumulator_true_handled (PyObject *unused, PyObject *args);
+PyObject *  pyg_add_emission_hook               (PyGObject *self, PyObject *args);
+PyObject *  pyg__install_metaclass              (PyObject *dummy,
+                                                 PyTypeObject *metaclass);
+PyObject *  pyg__gvalue_get                     (PyObject *module, PyObject *pygvalue);
+PyObject *  pyg__gvalue_set                     (PyObject *module, PyObject *args);
+
 #endif /*_PYGOBJECT_GOBJECTMODULE_H_*/
diff --git a/gi/module.py b/gi/module.py
index fd8f508..0b22634 100644
--- a/gi/module.py
+++ b/gi/module.py
@@ -53,13 +53,11 @@ from ._gi import \
     enum_register_new_gtype_and_add, \
     flags_add, \
     flags_register_new_gtype_and_add, \
-    _gobject
+    GInterface
 from .types import \
     GObjectMeta, \
     StructMeta
 
-GInterface = _gobject.GInterface
-
 from ._constants import \
     TYPE_NONE, \
     TYPE_BOXED, \
@@ -82,7 +80,7 @@ def get_parent_for_object(object_info):
         # for an existing wrapper on the GType and use it as a base for the
         # new introspection wrapper. This allows static C wrappers already
         # registered with the GType to be used as the introspection base
-        # (_gobject.GObject for example)
+        # (_gi.GObject for example)
         gtype = object_info.get_g_type()
         if gtype and gtype.pytype:
             return gtype.pytype
diff --git a/gi/overrides/GLib.py b/gi/overrides/GLib.py
index a146380..372d6d4 100644
--- a/gi/overrides/GLib.py
+++ b/gi/overrides/GLib.py
@@ -41,7 +41,6 @@ __all__.append('option')
 
 # Types and functions still needed from static bindings
 from gi import _gi
-from gi._gi import _gobject
 from gi._error import GError
 
 Error = GError
@@ -552,7 +551,7 @@ for name in ['G_MINFLOAT', 'G_MAXFLOAT', 'G_MINDOUBLE', 'G_MAXDOUBLE',
              'G_MAXUINT', 'G_MINLONG', 'G_MAXLONG', 'G_MAXULONG', 'G_MAXSIZE',
              'G_MINSSIZE', 'G_MAXSSIZE', 'G_MINOFFSET', 'G_MAXOFFSET']:
     attr = name.split("_", 1)[-1]
-    globals()[attr] = getattr(_gobject, name)
+    globals()[attr] = getattr(_gi, name)
     __all__.append(attr)
 
 
diff --git a/gi/overrides/GObject.py b/gi/overrides/GObject.py
index 2e8f755..c252bfa 100644
--- a/gi/overrides/GObject.py
+++ b/gi/overrides/GObject.py
@@ -33,8 +33,8 @@ from gi import PyGIDeprecationWarning
 
 from gi import _propertyhelper as propertyhelper
 from gi import _signalhelper as signalhelper
+from gi import _gi
 
-_gobject = gi._gi._gobject
 
 GObjectModule = gi.module.get_introspection_module('GObject')
 
@@ -42,7 +42,7 @@ __all__ = []
 
 
 from gi import _option as option
-sys.modules['gi._gobject.option'] = option
+option = option
 
 
 # API aliases for backwards compatibility
@@ -184,27 +184,27 @@ for name in ['SIGNAL_ACTION', 'SIGNAL_DETAILED', 'SIGNAL_NO_HOOKS',
     __all__.append(name)
 
 # Static types
-GBoxed = _gobject.GBoxed
-GEnum = _gobject.GEnum
-GFlags = _gobject.GFlags
-GInterface = _gobject.GInterface
-GObject = _gobject.GObject
-GObjectWeakRef = _gobject.GObjectWeakRef
-GParamSpec = _gobject.GParamSpec
-GPointer = _gobject.GPointer
-GType = _gobject.GType
-Warning = _gobject.Warning
+GBoxed = _gi.GBoxed
+GEnum = _gi.GEnum
+GFlags = _gi.GFlags
+GInterface = _gi.GInterface
+GObject = _gi.GObject
+GObjectWeakRef = _gi.GObjectWeakRef
+GParamSpec = _gi.GParamSpec
+GPointer = _gi.GPointer
+GType = _gi.GType
+Warning = _gi.Warning
 __all__ += ['GBoxed', 'GEnum', 'GFlags', 'GInterface', 'GObject',
             'GObjectWeakRef', 'GParamSpec', 'GPointer', 'GType',
             'Warning']
 
 
-features = _gobject.features
-list_properties = _gobject.list_properties
-new = _gobject.new
-pygobject_version = _gobject.pygobject_version
+features = _gi.features
+list_properties = _gi.list_properties
+new = _gi.new
+pygobject_version = _gi.pygobject_version
 threads_init = GLib.threads_init
-type_register = _gobject.type_register
+type_register = _gi.type_register
 __all__ += ['features', 'list_properties', 'new',
             'pygobject_version', 'threads_init', 'type_register']
 
@@ -228,15 +228,15 @@ class Value(GObjectModule.Value):
         # Workaround the introspection marshalers inability to know
         # these methods should be marshaling boxed types. This is because
         # the type information is stored on the GValue.
-        _gobject._gvalue_set(self, boxed)
+        _gi._gvalue_set(self, boxed)
 
     def get_boxed(self):
-        return _gobject._gvalue_get(self)
+        return _gi._gvalue_get(self)
 
     def set_value(self, py_value):
         gtype = self.g_type
 
-        if gtype == _gobject.TYPE_INVALID:
+        if gtype == _gi.TYPE_INVALID:
             raise TypeError("GObject.Value needs to be initialized first")
         elif gtype == TYPE_BOOLEAN:
             self.set_boolean(py_value)
@@ -527,8 +527,8 @@ __all__.append('signal_accumulator_true_handled')
 
 # Statically bound signal functions which need to clobber GI (for now)
 
-add_emission_hook = _gobject.add_emission_hook
-signal_new = _gobject.signal_new
+add_emission_hook = _gi.add_emission_hook
+signal_new = _gi.signal_new
 
 __all__ += ['add_emission_hook', 'signal_new']
 
@@ -596,23 +596,23 @@ class Object(GObjectModule.Object):
 
     # The following methods are static APIs which need to leap frog the
     # gi methods until we verify the gi methods can replace them.
-    get_property = _gobject.GObject.get_property
-    get_properties = _gobject.GObject.get_properties
-    set_property = _gobject.GObject.set_property
-    set_properties = _gobject.GObject.set_properties
-    bind_property = _gobject.GObject.bind_property
-    connect = _gobject.GObject.connect
-    connect_after = _gobject.GObject.connect_after
-    connect_object = _gobject.GObject.connect_object
-    connect_object_after = _gobject.GObject.connect_object_after
-    disconnect_by_func = _gobject.GObject.disconnect_by_func
-    handler_block_by_func = _gobject.GObject.handler_block_by_func
-    handler_unblock_by_func = _gobject.GObject.handler_unblock_by_func
-    emit = _gobject.GObject.emit
-    chain = _gobject.GObject.chain
-    weak_ref = _gobject.GObject.weak_ref
-    __copy__ = _gobject.GObject.__copy__
-    __deepcopy__ = _gobject.GObject.__deepcopy__
+    get_property = _gi.GObject.get_property
+    get_properties = _gi.GObject.get_properties
+    set_property = _gi.GObject.set_property
+    set_properties = _gi.GObject.set_properties
+    bind_property = _gi.GObject.bind_property
+    connect = _gi.GObject.connect
+    connect_after = _gi.GObject.connect_after
+    connect_object = _gi.GObject.connect_object
+    connect_object_after = _gi.GObject.connect_object_after
+    disconnect_by_func = _gi.GObject.disconnect_by_func
+    handler_block_by_func = _gi.GObject.handler_block_by_func
+    handler_unblock_by_func = _gi.GObject.handler_unblock_by_func
+    emit = _gi.GObject.emit
+    chain = _gi.GObject.chain
+    weak_ref = _gi.GObject.weak_ref
+    __copy__ = _gi.GObject.__copy__
+    __deepcopy__ = _gi.GObject.__deepcopy__
 
     def freeze_notify(self):
         """Freezes the object's property-changed notification queue.
@@ -648,9 +648,9 @@ class Object(GObjectModule.Object):
         """
         flags = kwargs.get('connect_flags', 0)
         if flags & GObjectModule.ConnectFlags.AFTER:
-            connect_func = _gobject.GObject.connect_after
+            connect_func = _gi.GObject.connect_after
         else:
-            connect_func = _gobject.GObject.connect
+            connect_func = _gi.GObject.connect
 
         if flags & GObjectModule.ConnectFlags.SWAPPED:
             if len(data) != 1:
diff --git a/gi/pygi-value.c b/gi/pygi-value.c
index 3d81e7b..443597c 100644
--- a/gi/pygi-value.c
+++ b/gi/pygi-value.c
@@ -579,7 +579,7 @@ pyg_value_from_pyobject_with_error(GValue *value, PyObject *obj)
         break;
     }
     case G_TYPE_PARAM:
-        /* we need to support both the wrapped _gobject.GParamSpec and the GI
+        /* we need to support both the wrapped _gi.GParamSpec and the GI
          * GObject.ParamSpec */
         if (G_IS_PARAM_SPEC (pygobject_get (obj)))
             g_value_set_param(value, G_PARAM_SPEC (pygobject_get (obj)));
diff --git a/gi/pygobject-object.c b/gi/pygobject-object.c
index 1e51f38..ca82ffb 100644
--- a/gi/pygobject-object.c
+++ b/gi/pygobject-object.c
@@ -206,7 +206,7 @@ typedef struct {
     guint index;
 } PyGPropsIter;
 
-PYGLIB_DEFINE_TYPE("gi._gobject.GPropsIter", PyGPropsIter_Type, PyGPropsIter);
+PYGLIB_DEFINE_TYPE("gi._gi.GPropsIter", PyGPropsIter_Type, PyGPropsIter);
 
 static void
 pyg_props_iter_dealloc(PyGPropsIter *self)
@@ -351,7 +351,7 @@ set_property_from_pspec(GObject *obj,
     return TRUE;
 }
 
-PYGLIB_DEFINE_TYPE("gi._gobject.GProps", PyGProps_Type, PyGProps);
+PYGLIB_DEFINE_TYPE("gi._gi.GProps", PyGProps_Type, PyGProps);
 
 static int
 PyGProps_setattro(PyGProps *self, PyObject *attr, PyObject *pvalue)
@@ -477,7 +477,7 @@ static PySequenceMethods _PyGProps_as_sequence = {
     0
 };
 
-PYGLIB_DEFINE_TYPE("gi._gobject.GPropsDescr", PyGPropsDescr_Type, PyObject);
+PYGLIB_DEFINE_TYPE("gi._gi.GPropsDescr", PyGPropsDescr_Type, PyObject);
 
 static PyObject *
 pyg_props_descr_descr_get(PyObject *self, PyObject *obj, PyObject *type)
@@ -1072,7 +1072,7 @@ pygobject_watch_closure(PyObject *self, GClosure *closure)
 
 /* -------------- PyGObject behaviour ----------------- */
 
-PYGLIB_DEFINE_TYPE("gi._gobject.GObject", PyGObject_Type, PyGObject);
+PYGLIB_DEFINE_TYPE("gi._gi.GObject", PyGObject_Type, PyGObject);
 
 static void
 pygobject_dealloc(PyGObject *self)
@@ -2206,7 +2206,7 @@ typedef struct {
     gboolean have_floating_ref;
 } PyGObjectWeakRef;
 
-PYGLIB_DEFINE_TYPE("gi._gobject.GObjectWeakRef", PyGObjectWeakRef_Type, PyGObjectWeakRef);
+PYGLIB_DEFINE_TYPE("gi._gi.GObjectWeakRef", PyGObjectWeakRef_Type, PyGObjectWeakRef);
 
 static int
 pygobject_weak_ref_traverse(PyGObjectWeakRef *self, visitproc visit, void *arg)
@@ -2410,7 +2410,7 @@ pygobject_object_register_types(PyObject *d)
     descr = PyObject_New(PyObject, &PyGPropsDescr_Type);
     PyDict_SetItemString(PyGObject_Type.tp_dict, "props", descr);
     PyDict_SetItemString(PyGObject_Type.tp_dict, "__module__",
-                        o=PYGLIB_PyUnicode_FromString("gi._gobject._gobject"));
+                        o=PYGLIB_PyUnicode_FromString("gi._gi"));
     Py_DECREF(o);
 
     /* GPropsIter */
diff --git a/gi/types.py b/gi/types.py
index 9d3cb0c..9bc3779 100644
--- a/gi/types.py
+++ b/gi/types.py
@@ -35,11 +35,10 @@ from ._gi import \
     VFuncInfo, \
     register_interface_info, \
     hook_up_vfunc_implementation, \
-    _gobject
+    GInterface
+from . import _gi
 
-GInterface = _gobject.GInterface
-
-StructInfo  # pyflakes
+StructInfo, GInterface  # pyflakes
 
 from . import _propertyhelper as propertyhelper
 from . import _signalhelper as signalhelper
@@ -147,7 +146,7 @@ def find_vfunc_info_in_interface(bases, vfunc_name):
         # This can be seen in IntrospectionModule.__getattr__() in module.py.
         # We do not need to search regular classes here, only wrapped interfaces.
         # We also skip GInterface, because it is not wrapped and has no __info__ attr.
-        # Skip bases without __info__ (static _gobject._gobject.GObject)
+        # Skip bases without __info__ (static _gi.GObject)
         if base is GInterface or\
                 not issubclass(base, GInterface) or\
                 not hasattr(base, '__info__'):
@@ -202,10 +201,10 @@ class _GObjectMetaBase(type):
         if cls.__module__.startswith('gi.overrides.'):
             return
 
-        _gobject.type_register(cls, namespace.get('__gtype_name__'))
+        _gi.type_register(cls, namespace.get('__gtype_name__'))
 
 
-_gobject._install_metaclass(_GObjectMetaBase)
+_gi._install_metaclass(_GObjectMetaBase)
 
 
 class GObjectMeta(_GObjectMetaBase, MetaClassHelper):
diff --git a/tests/helper.py b/tests/helper.py
index c4308fe..4ac3dfe 100644
--- a/tests/helper.py
+++ b/tests/helper.py
@@ -88,7 +88,7 @@ def capture_glib_warnings(allow_warnings=False, allow_criticals=False):
 
     GLib.log_set_always_fatal(GLib.LogLevelFlags(new_mask))
 
-    GLibWarning = gi._gi._gobject.Warning
+    GLibWarning = gi._gi.Warning
     try:
         with warnings.catch_warnings(record=True) as warn:
             warnings.filterwarnings('always', category=GLibWarning)
@@ -101,7 +101,7 @@ def capture_glib_warnings(allow_warnings=False, allow_criticals=False):
 def capture_glib_deprecation_warnings():
     """Temporarily suppress glib deprecation warning output and record them"""
 
-    GLibWarning = gi._gi._gobject.Warning
+    GLibWarning = gi._gi.Warning
     with warnings.catch_warnings(record=True) as warn:
         warnings.filterwarnings(
             'always', category=GLibWarning,
diff --git a/tests/test_gi.py b/tests/test_gi.py
index ffad4ad..16d0d53 100644
--- a/tests/test_gi.py
+++ b/tests/test_gi.py
@@ -2707,7 +2707,7 @@ class TestMRO(unittest.TestCase):
             pass
 
         expected = (E, D, B, C, A, GIMarshallingTests.Object,
-                    GObject.Object, GObject.Object.__base__, gi._gi._gobject.GObject,
+                    GObject.Object, GObject.Object.__base__, gi._gi.GObject,
                     object)
         self.assertEqual(expected, E.__mro__)
 
diff --git a/tests/test_gobject.py b/tests/test_gobject.py
index 19ef03c..c380d72 100644
--- a/tests/test_gobject.py
+++ b/tests/test_gobject.py
@@ -8,9 +8,7 @@ import warnings
 from gi.repository import GObject, GLib
 from gi import PyGIDeprecationWarning
 from gi.module import get_introspection_module
-
-import gi
-_gobject = gi._gi._gobject
+from gi import _gi
 
 import testhelper
 
@@ -27,9 +25,9 @@ class TestGObjectAPI(unittest.TestCase):
         # overrides.Object -> introspection.Object -> static.GObject
         GIObjectModule = get_introspection_module('GObject')
         self.assertTrue(issubclass(GObject.Object, GIObjectModule.Object))
-        self.assertTrue(issubclass(GIObjectModule.Object, _gobject.GObject))
+        self.assertTrue(issubclass(GIObjectModule.Object, _gi.GObject))
 
-        self.assertEqual(_gobject.GObject.__gtype__, GObject.TYPE_OBJECT)
+        self.assertEqual(_gi.GObject.__gtype__, GObject.TYPE_OBJECT)
         self.assertEqual(GIObjectModule.Object.__gtype__, GObject.TYPE_OBJECT)
         self.assertEqual(GObject.Object.__gtype__, GObject.TYPE_OBJECT)
 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]