[pygobject] Skip gi.CallbackInfo objects from a module's dir()



commit 3235f1a397c334de5a7570f5ceed4da709fe1714
Author: Martin Pitt <martinpitt gnome org>
Date:   Mon Jul 16 15:53:31 2012 +0200

    Skip gi.CallbackInfo objects from a module's dir()
    
    Skip gi.CallbackInfo items from IntrospectionModule's __dir__(), as we do not
    implement __getattr__ for those.
    
    Add a test case that dir() works on GI modules, contain expected identifiers,
    and that all identifiers in dir() can actually be retrieved.
    
    Prerequisite for https://bugzilla.gnome.org/show_bug.cgi?id=679804

 gi/module.py     |    7 +++++--
 tests/test_gi.py |   14 ++++++++++++++
 2 files changed, 19 insertions(+), 2 deletions(-)
---
diff --git a/gi/module.py b/gi/module.py
index 566b40d..2d26823 100644
--- a/gi/module.py
+++ b/gi/module.py
@@ -218,9 +218,12 @@ class IntrospectionModule(object):
         result.update(self.__dict__.keys())
 
         # update *set* because some repository attributes have already been
-        # wrapped by __getattr__() and included in self.__dict__
+        # wrapped by __getattr__() and included in self.__dict__; but skip
+        # Callback types, as these are not real objects which we can actually
+        # get
         namespace_infos = repository.get_infos(self._namespace)
-        result.update(info.get_name() for info in namespace_infos)
+        result.update(info.get_name() for info in namespace_infos if
+                      not isinstance(info, CallbackInfo))
 
         return list(result)
 
diff --git a/tests/test_gi.py b/tests/test_gi.py
index 419f806..9d014ee 100644
--- a/tests/test_gi.py
+++ b/tests/test_gi.py
@@ -2260,3 +2260,17 @@ class TestModule(unittest.TestCase):
     def test_str(self):
         self.assertTrue("'GIMarshallingTests' from '" in str(GIMarshallingTests),
                         str(GIMarshallingTests))
+
+    def test_dir(self):
+        _dir = dir(GIMarshallingTests)
+        self.assertGreater(len(_dir), 10)
+
+        self.assertTrue('SimpleStruct' in _dir)
+        self.assertTrue('Interface2' in _dir)
+        self.assertTrue('CONSTANT_GERROR_CODE' in _dir)
+        self.assertTrue('array_zero_terminated_inout' in _dir)
+
+        # assert that dir() does not contain garbage
+        for item_name in _dir:
+            item = getattr(GIMarshallingTests, item_name)
+            self.assertTrue(hasattr(item, '__class__'))



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