[pygobject] Change boxed init with args to warn instead of raise



commit 27a14679dce33f64bbb5d77677eba83849f168ff
Author: Christoph Reiter <reiter christoph gmail com>
Date:   Fri Aug 22 21:51:31 2014 -0700

    Change boxed init with args to warn instead of raise
    
    Replace raising a TypeError in gi.types.Boxed() with a warning.
    Even though passing arguments or keywords to the parent class is
    incorrect here, raising an exception was causing a bit of fallout
    in some apps (Gramps).
    
    https://bugzilla.gnome.org/show_bug.cgi?id=727810

 gi/pygi-boxed.c  |    5 ++++-
 tests/test_gi.py |   13 +++++++++++--
 2 files changed, 15 insertions(+), 3 deletions(-)
---
diff --git a/gi/pygi-boxed.c b/gi/pygi-boxed.c
index 557584b..a1494b6 100644
--- a/gi/pygi-boxed.c
+++ b/gi/pygi-boxed.c
@@ -134,7 +134,10 @@ _boxed_init (PyObject *self,
     static char *kwlist[] = { NULL };
 
     if (!PyArg_ParseTupleAndKeywords (args, kwargs, "", kwlist)) {
-        return -1;
+        PyErr_Clear ();
+        PyErr_Warn (PyExc_TypeError,
+                "Passing arguments to gi.types.Boxed.__init__() is deprecated. "
+                "All arguments passed will be ignored.");
     }
 
     /* Don't call PyGBoxed's init, which raises an exception. */
diff --git a/tests/test_gi.py b/tests/test_gi.py
index e8c3aad..20c7343 100644
--- a/tests/test_gi.py
+++ b/tests/test_gi.py
@@ -1868,8 +1868,17 @@ class TestStructure(unittest.TestCase):
         self.assertEqual(struct.string_, 'hello')
 
     def test_union_init(self):
-        self.assertRaises(TypeError, GIMarshallingTests.Union, 42)
-        self.assertRaises(TypeError, GIMarshallingTests.Union, f=42)
+        with warnings.catch_warnings(record=True) as warn:
+            warnings.simplefilter('always')
+            GIMarshallingTests.Union(42)
+
+        self.assertTrue(issubclass(warn[0].category, TypeError))
+
+        with warnings.catch_warnings(record=True) as warn:
+            warnings.simplefilter('always')
+            GIMarshallingTests.Union(f=42)
+
+        self.assertTrue(issubclass(warn[0].category, TypeError))
 
     def test_union(self):
         union = GIMarshallingTests.Union()


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