[pygobject] Instead of printing an error, raise an exception



commit 26dfaaa934f98141da3ac22dfb6d45f20757bea5
Author: Arjan Molenaar <gaphor gmail com>
Date:   Wed Aug 25 21:53:59 2021 +0200

    Instead of printing an error, raise an exception

 gi/pygi-object.c             | 8 +++++---
 tests/test_gtype_instance.py | 8 ++++++++
 2 files changed, 13 insertions(+), 3 deletions(-)
---
diff --git a/gi/pygi-object.c b/gi/pygi-object.c
index ec527f55..efa2cacb 100644
--- a/gi/pygi-object.c
+++ b/gi/pygi-object.c
@@ -240,9 +240,10 @@ pygi_arg_gobject_to_py (GIArgument *arg, GITransfer transfer) {
                                      /*steal=*/ transfer == GI_TRANSFER_EVERYTHING,
                                      /*type=*/  NULL);
     } else {
-        g_critical("No means to translate argument or return value for '%s'", 
g_type_name_from_instance(arg->v_pointer));
-        pyobj = Py_None;
-        Py_INCREF (pyobj);
+        PyErr_Format(PyExc_TypeError,
+                     "No means to translate argument or return value for '%s'",
+                     g_type_name_from_instance(arg->v_pointer));
+        return NULL;
     }
 
     return pyobj;
@@ -265,6 +266,7 @@ pygi_arg_gobject_to_py_called_from_c (GIArgument *arg,
      */
     if (arg->v_pointer != NULL &&
             transfer == GI_TRANSFER_NOTHING &&
+            // Should check for G_IS_OBJECT instead
             !G_IS_PARAM_SPEC (arg->v_pointer) &&
             g_object_is_floating (arg->v_pointer)) {
 
diff --git a/tests/test_gtype_instance.py b/tests/test_gtype_instance.py
new file mode 100644
index 00000000..a2f7eec5
--- /dev/null
+++ b/tests/test_gtype_instance.py
@@ -0,0 +1,8 @@
+
+import pytest
+from gi.repository import Regress
+
+
+def test_fundamental_type_instantiation_fails():
+    with pytest.raises(TypeError, match="No means to translate argument or return value for 
'RegressTestFundamentalSubObject'"):
+        Regress.TestFundamentalSubObject.new("data")


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