[pygobject] Move TYPE constants from _gobject to GObject



commit 2a24c9ccd59bff719fa817a0ec5c959f6da03e1c
Author: Simon Feltman <sfeltman src gnome org>
Date:   Sun Nov 4 22:22:53 2012 -0800

    Move TYPE constants from _gobject to GObject
    
    Clear out TYPE constants from _gobject/__init__.py and move them into the
    GObject overrides. Disperse class imports among modules that use them instead
    of using _gobject/__init__.py as a staging area (e.g. GInterface).
    
    https://bugzilla.gnome.org/show_bug.cgi?id=687487

 gi/_gobject/__init__.py  |   30 ------------------------------
 gi/_gobject/constants.py |    2 +-
 gi/module.py             |   38 +++++++++++++++++++++++++-------------
 gi/overrides/__init__.py |    9 ++++++---
 gi/types.py              |   10 ++++++----
 5 files changed, 38 insertions(+), 51 deletions(-)
---
diff --git a/gi/_gobject/__init__.py b/gi/_gobject/__init__.py
index 21f4e86..d3ea0e0 100644
--- a/gi/_gobject/__init__.py
+++ b/gi/_gobject/__init__.py
@@ -28,45 +28,15 @@ if 'gobject' in sys.modules:
     raise ImportError('When using gi.repository you must not import static modules like "gobject". Please change all occurrences of "import gobject" to "from gi.repository import GObject".')
 
 from . import _gobject
-from . import constants
 from . import propertyhelper
 from . import signalhelper
 
-GInterface = _gobject.GInterface
 GObject = _gobject.GObject
 GType = _gobject.GType
-TYPE_INVALID = _gobject.TYPE_INVALID
 _PyGObject_API = _gobject._PyGObject_API
 pygobject_version = _gobject.pygobject_version
 
 
-TYPE_NONE = constants.TYPE_NONE
-TYPE_INTERFACE = constants.TYPE_INTERFACE
-TYPE_CHAR = constants.TYPE_CHAR
-TYPE_UCHAR = constants.TYPE_UCHAR
-TYPE_BOOLEAN = constants.TYPE_BOOLEAN
-TYPE_INT = constants.TYPE_INT
-TYPE_UINT = constants.TYPE_UINT
-TYPE_LONG = constants.TYPE_LONG
-TYPE_ULONG = constants.TYPE_ULONG
-TYPE_INT64 = constants.TYPE_INT64
-TYPE_UINT64 = constants.TYPE_UINT64
-TYPE_ENUM = constants.TYPE_ENUM
-TYPE_FLAGS = constants.TYPE_FLAGS
-TYPE_FLOAT = constants.TYPE_FLOAT
-TYPE_DOUBLE = constants.TYPE_DOUBLE
-TYPE_STRING = constants.TYPE_STRING
-TYPE_POINTER = constants.TYPE_POINTER
-TYPE_BOXED = constants.TYPE_BOXED
-TYPE_PARAM = constants.TYPE_PARAM
-TYPE_OBJECT = constants.TYPE_OBJECT
-TYPE_PYOBJECT = constants.TYPE_PYOBJECT
-TYPE_GTYPE = constants.TYPE_GTYPE
-TYPE_UNICHAR = constants.TYPE_UNICHAR
-TYPE_STRV = constants.TYPE_STRV
-TYPE_VARIANT = constants.TYPE_VARIANT
-
-
 class GObjectMeta(type):
     "Metaclass for automatically registering GObject classes"
     def __init__(cls, name, bases, dict_):
diff --git a/gi/_gobject/constants.py b/gi/_gobject/constants.py
index 38a6e3d..9565a66 100644
--- a/gi/_gobject/constants.py
+++ b/gi/_gobject/constants.py
@@ -21,7 +21,7 @@
 
 from . import _gobject
 
-# TYPE_INVALID defined in gobjectmodule.c
+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')
diff --git a/gi/module.py b/gi/module.py
index 7e1ae0f..1138871 100644
--- a/gi/module.py
+++ b/gi/module.py
@@ -27,7 +27,7 @@ import types
 
 _have_py3 = (sys.version_info[0] >= 3)
 
-from . import _glib, _gobject
+from . import _glib
 try:
     maketrans = ''.maketrans
 except AttributeError:
@@ -60,6 +60,18 @@ from .types import \
     StructMeta, \
     Function
 
+from ._gobject._gobject import \
+    GInterface, \
+    GObject
+
+from ._gobject.constants import \
+    TYPE_NONE, \
+    TYPE_BOXED, \
+    TYPE_POINTER, \
+    TYPE_ENUM, \
+    TYPE_FLAGS
+
+
 repository = Repository.get_default()
 
 # Cache of IntrospectionModules that have been loaded.
@@ -77,7 +89,7 @@ def get_parent_for_object(object_info):
 
     # Workaround for GObject.Object and GObject.InitiallyUnowned.
     if namespace == 'GObject' and name == 'Object' or name == 'InitiallyUnowned':
-        return _gobject.GObject
+        return GObject
 
     module = __import__('gi.repository.%s' % namespace, fromlist=[name])
     return getattr(module, name)
@@ -129,16 +141,16 @@ class IntrospectionModule(object):
 
             if wrapper is None:
                 if info.is_flags():
-                    if g_type.is_a(_gobject.TYPE_FLAGS):
+                    if g_type.is_a(TYPE_FLAGS):
                         wrapper = flags_add(g_type)
                     else:
-                        assert g_type == _gobject.TYPE_NONE
+                        assert g_type == TYPE_NONE
                         wrapper = flags_register_new_gtype_and_add(info)
                 else:
-                    if g_type.is_a(_gobject.TYPE_ENUM):
+                    if g_type.is_a(TYPE_ENUM):
                         wrapper = enum_add(g_type)
                     else:
-                        assert g_type == _gobject.TYPE_NONE
+                        assert g_type == TYPE_NONE
                         wrapper = enum_register_new_gtype_and_add(info)
 
                 wrapper.__info__ = info
@@ -154,14 +166,14 @@ class IntrospectionModule(object):
                     value_name = value_info.get_name_unescaped().translate(ascii_upper_trans)
                     setattr(wrapper, value_name, wrapper(value_info.get_value()))
 
-            if g_type != _gobject.TYPE_NONE:
+            if g_type != TYPE_NONE:
                 g_type.pytype = wrapper
 
         elif isinstance(info, RegisteredTypeInfo):
             g_type = info.get_g_type()
 
             # Check if there is already a Python wrapper.
-            if g_type != _gobject.TYPE_NONE:
+            if g_type != TYPE_NONE:
                 type_ = g_type.pytype
                 if type_ is not None:
                     self.__dict__[name] = type_
@@ -178,13 +190,13 @@ class IntrospectionModule(object):
                 bases = (CCallback,)
                 metaclass = GObjectMeta
             elif isinstance(info, InterfaceInfo):
-                bases = (_gobject.GInterface,)
+                bases = (GInterface,)
                 metaclass = GObjectMeta
             elif isinstance(info, (StructInfo, UnionInfo)):
-                if g_type.is_a(_gobject.TYPE_BOXED):
+                if g_type.is_a(TYPE_BOXED):
                     bases = (Boxed,)
-                elif (g_type.is_a(_gobject.TYPE_POINTER) or
-                      g_type == _gobject.TYPE_NONE or
+                elif (g_type.is_a(TYPE_POINTER) or
+                      g_type == TYPE_NONE or
                       g_type.fundamental == g_type):
                     bases = (Struct,)
                 else:
@@ -202,7 +214,7 @@ class IntrospectionModule(object):
             wrapper = metaclass(name, bases, dict_)
 
             # Register the new Python wrapper.
-            if g_type != _gobject.TYPE_NONE:
+            if g_type != TYPE_NONE:
                 g_type.pytype = wrapper
 
         elif isinstance(info, FunctionInfo):
diff --git a/gi/overrides/__init__.py b/gi/overrides/__init__.py
index 4487d7c..b7d365c 100644
--- a/gi/overrides/__init__.py
+++ b/gi/overrides/__init__.py
@@ -2,7 +2,10 @@ import types
 import warnings
 import functools
 
-from gi import _gobject, PyGIDeprecationWarning
+from gi import PyGIDeprecationWarning
+from gi._gobject.constants import \
+    TYPE_NONE, \
+    TYPE_INVALID
 
 # support overrides in different directories than our gi module
 from pkgutil import extend_path
@@ -33,8 +36,8 @@ class _Registry(dict):
             raise KeyError('You have tried to modify the registry outside of the overrides module.  This is not allowed')
 
         g_type = info.get_g_type()
-        assert g_type != _gobject.TYPE_NONE
-        if g_type != _gobject.TYPE_INVALID:
+        assert g_type != TYPE_NONE
+        if g_type != TYPE_INVALID:
             g_type.pytype = value
 
             # strip gi.overrides from module name
diff --git a/gi/types.py b/gi/types.py
index 3b94294..945d3b6 100644
--- a/gi/types.py
+++ b/gi/types.py
@@ -24,6 +24,8 @@ from __future__ import absolute_import
 
 import sys
 from . import _gobject
+from ._gobject._gobject import GInterface
+from ._gobject.constants import TYPE_INVALID
 
 from ._gi import \
     InterfaceInfo, \
@@ -181,8 +183,8 @@ 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.
-        if base is _gobject.GInterface or\
-                not issubclass(base, _gobject.GInterface) or\
+        if base is GInterface or\
+                not issubclass(base, GInterface) or\
                 not isinstance(base.__info__, InterfaceInfo):
             continue
 
@@ -260,7 +262,7 @@ def mro(C):
         for subclass_bases in bases_of_subclasses:
             candidate = subclass_bases[0]
             not_head = [s for s in bases_of_subclasses if candidate in s[1:]]
-            if not_head and _gobject.GInterface not in candidate.__bases__:
+            if not_head and GInterface not in candidate.__bases__:
                 candidate = None  # conflict, reject candidate
             else:
                 break
@@ -287,7 +289,7 @@ class StructMeta(type, MetaClassHelper):
 
         # Avoid touching anything else than the base class.
         g_type = cls.__info__.get_g_type()
-        if g_type != _gobject.TYPE_INVALID and g_type.pytype is not None:
+        if g_type != TYPE_INVALID and g_type.pytype is not None:
             return
 
         cls._setup_fields()



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