[pygobject] In IntrospectionModule and DynamicModule classes, make all instance attributes start with an undersc



commit 09c21c79fb6063c8451f53d4588363d2be7239f4
Author: Laszlo Pandy <lpandy src gnome org>
Date:   Mon Jan 17 16:46:08 2011 +0100

    In IntrospectionModule and DynamicModule classes, make all instance attributes start with an underscore.
    
    This changes IntrospectionModule.version to _version and DynamicModule.introspection_module to _introspection_module.
    This is done to mark the attributes as private, and also avoid name collisions with attributes from the typelib.
    In Gstreamer, there is a function gst_version, which was previously inaccessible because of IntrospectionModule.version overriding it.

 gi/module.py                       |   26 +++++++++++++-------------
 gi/overrides/GIMarshallingTests.py |    2 +-
 gi/overrides/GLib.py               |    2 +-
 gi/overrides/Gdk.py                |   10 +++++-----
 gi/overrides/Gtk.py                |    2 +-
 gi/overrides/Pango.py              |    2 +-
 gi/overrides/__init__.py           |    2 +-
 tests/test_everything.py           |    2 +-
 8 files changed, 24 insertions(+), 24 deletions(-)
---
diff --git a/gi/module.py b/gi/module.py
index 98d089a..9b935ed 100644
--- a/gi/module.py
+++ b/gi/module.py
@@ -82,14 +82,14 @@ class IntrospectionModule(object):
     def __init__(self, namespace, version=None):
         repository.require(namespace, version)
         self._namespace = namespace
-        self.version = version
+        self._version = version
         self.__name__ = 'gi.repository.' + namespace
 
-        repository.require(self._namespace, self.version)
+        repository.require(self._namespace, self._version)
         self.__path__ = repository.get_typelib_path(self._namespace)
 
-        if self.version is None:
-            self.version = repository.get_version(self._namespace)
+        if self._version is None:
+            self._version = repository.get_version(self._namespace)
 
     def __getattr__(self, name):
         info = repository.find_by_name(self._namespace, name)
@@ -223,27 +223,27 @@ class DynamicGObjectModule(IntrospectionModule):
 class DynamicModule(object):
     def __init__(self, namespace):
         self._namespace = namespace
-        self.introspection_module = None
+        self._introspection_module = None
         self._version = None
         self._overrides_module = None
         self.__path__ = None
 
     def require_version(self, version):
-        if self.introspection_module is not None and \
-                self.introspection_module.version != version:
+        if self._introspection_module is not None and \
+                self._introspection_module._version != version:
             raise RuntimeError('Module has been already loaded ')
         self._version = version
 
     def _import(self):
-        self.introspection_module = IntrospectionModule(self._namespace,
-                                                        self._version)
+        self._introspection_module = IntrospectionModule(self._namespace,
+                                                         self._version)
 
         overrides_modules = __import__('gi.overrides', fromlist=[self._namespace])
         self._overrides_module = getattr(overrides_modules, self._namespace, None)
         self.__path__ = repository.get_typelib_path(self._namespace)
 
     def __getattr__(self, name):
-        if self.introspection_module is None:
+        if self._introspection_module is None:
             self._import()
 
         if self._overrides_module is not None:
@@ -260,17 +260,17 @@ class DynamicModule(object):
             if key in registry:
                 return registry[key]
 
-        return getattr(self.introspection_module, name)
+        return getattr(self._introspection_module, name)
 
     def __dir__ (self):
-        if self.introspection_module is None:
+        if self._introspection_module is None:
             self._import()
             
         # Python's default dir() is just dir(self.__class__) + self.__dict__.keys()
         result = set(dir(self.__class__))
         result.update(self.__dict__.keys())
         
-        result.update(dir(self.introspection_module))
+        result.update(dir(self._introspection_module))
         override_exports = getattr(self._overrides_module, '__all__', ())
         result.update(override_exports)
         return list(result)
diff --git a/gi/overrides/GIMarshallingTests.py b/gi/overrides/GIMarshallingTests.py
index 25a882f..aac8883 100644
--- a/gi/overrides/GIMarshallingTests.py
+++ b/gi/overrides/GIMarshallingTests.py
@@ -21,7 +21,7 @@
 from ..overrides import override
 from ..importer import modules
 
-GIMarshallingTests = modules['GIMarshallingTests'].introspection_module
+GIMarshallingTests = modules['GIMarshallingTests']._introspection_module
 
 __all__ = []
 
diff --git a/gi/overrides/GLib.py b/gi/overrides/GLib.py
index 78d8c35..13f34a4 100644
--- a/gi/overrides/GLib.py
+++ b/gi/overrides/GLib.py
@@ -21,7 +21,7 @@
 from ..importer import modules
 from .._gi import variant_new_tuple, variant_type_from_string
 
-GLib = modules['GLib'].introspection_module
+GLib = modules['GLib']._introspection_module
 
 __all__ = []
 
diff --git a/gi/overrides/Gdk.py b/gi/overrides/Gdk.py
index 624ff49..c87ed46 100644
--- a/gi/overrides/Gdk.py
+++ b/gi/overrides/Gdk.py
@@ -22,7 +22,7 @@
 from ..overrides import override
 from ..importer import modules
 
-Gdk = modules['Gdk'].introspection_module
+Gdk = modules['Gdk']._introspection_module
 
 __all__ = []
 
@@ -43,7 +43,7 @@ class Color(Gdk.Color):
 Color = override(Color)
 __all__.append('Color')
 
-if Gdk.version == '2.0':
+if Gdk._version == '2.0':
     class Rectangle(Gdk.Rectangle):
 
         def __init__(self, x, y, width, height):
@@ -62,7 +62,7 @@ if Gdk.version == '2.0':
     Rectangle = override(Rectangle)
     __all__.append('Rectangle')
 
-if Gdk.version == '2.0':
+if Gdk._version == '2.0':
     class Drawable(Gdk.Drawable):
         def cairo_create(self):
             return Gdk.cairo_create(self)
@@ -111,7 +111,7 @@ class Event(Gdk.Event):
         Gdk.EventType.VISIBILITY_NOTIFY: 'visibility',
     }
 
-    if Gdk.version == '2.0':
+    if Gdk._version == '2.0':
         _UNION_MEMBERS[Gdk.EventType.NO_EXPOSE] = 'no_expose'
 
     def __new__(cls, *args, **kwargs):
@@ -129,7 +129,7 @@ __all__.append('Event')
 
 class DragContext(Gdk.DragContext):
     def finish(self, success, del_, time):
-        Gtk = modules['Gtk'].introspection_module
+        Gtk = modules['Gtk']._introspection_module
         Gtk.drag_finish(self, success, del_, time)
 
 DragContext = override(DragContext)
diff --git a/gi/overrides/Gtk.py b/gi/overrides/Gtk.py
index 1db9025..22ab382 100644
--- a/gi/overrides/Gtk.py
+++ b/gi/overrides/Gtk.py
@@ -32,7 +32,7 @@ else:
     _basestring = basestring
     _callable = callable
 
-Gtk = modules['Gtk'].introspection_module
+Gtk = modules['Gtk']._introspection_module
 __all__ = []
 
 class Widget(Gtk.Widget):
diff --git a/gi/overrides/Pango.py b/gi/overrides/Pango.py
index 700d26d..714d35d 100644
--- a/gi/overrides/Pango.py
+++ b/gi/overrides/Pango.py
@@ -21,7 +21,7 @@
 from ..overrides import override
 from ..importer import modules
 
-Pango = modules['Pango'].introspection_module
+Pango = modules['Pango']._introspection_module
 
 __all__ = []
 
diff --git a/gi/overrides/__init__.py b/gi/overrides/__init__.py
index c634a2f..a98974f 100644
--- a/gi/overrides/__init__.py
+++ b/gi/overrides/__init__.py
@@ -44,7 +44,7 @@ class overridefunc(object):
         if not hasattr(func, '__info__'):
             raise TypeError("func must be an gi function")
         from ..importer import modules
-        self.module = modules[func.__module__].introspection_module
+        self.module = modules[func.__module__]._introspection_module
 
     def __call__(self, func):
         def wrapper(*args, **kwargs):
diff --git a/tests/test_everything.py b/tests/test_everything.py
index b2f2463..701c4ad 100644
--- a/tests/test_everything.py
+++ b/tests/test_everything.py
@@ -145,7 +145,7 @@ class TestEverything(unittest.TestCase):
         
         # test that instance members are listed
         self.assertTrue('_namespace' in attr_list)
-        self.assertTrue('version' in attr_list)
+        self.assertTrue('_version' in attr_list)
         
         # test that there are no duplicates returned
         self.assertEqual(len(attr_list), len(set(attr_list)))



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