[pygobject] GObject.Value: deprecate calling get/set_boxed on a non-boxed value



commit 59538e6b256b3ccd6bcaf42f02c151f2fcf23535
Author: Christoph Reiter <reiter christoph gmail com>
Date:   Fri Jan 18 18:40:35 2019 +0100

    GObject.Value: deprecate calling get/set_boxed on a non-boxed value
    
    This wasn't documented but worked in most cases. Make sure no-one is depending
    on it in the long run.

 gi/overrides/GObject.py         | 6 ++++++
 tests/test_overrides_gobject.py | 8 ++++++++
 2 files changed, 14 insertions(+)
---
diff --git a/gi/overrides/GObject.py b/gi/overrides/GObject.py
index 938a19a8..4cc08a9a 100644
--- a/gi/overrides/GObject.py
+++ b/gi/overrides/GObject.py
@@ -210,12 +210,18 @@ class Value(GObjectModule.Value):
                 self.set_value(py_value)
 
     def set_boxed(self, boxed):
+        if not self.g_type.is_a(TYPE_BOXED):
+            warnings.warn('Calling set_boxed() on a non-boxed type deprecated',
+                          PyGIDeprecationWarning, stacklevel=2)
         # Workaround the introspection marshalers inability to know
         # these methods should be marshaling boxed types. This is because
         # the type information is stored on the GValue.
         _gi._gvalue_set(self, boxed)
 
     def get_boxed(self):
+        if not self.g_type.is_a(TYPE_BOXED):
+            warnings.warn('Calling get_boxed() on a non-boxed type deprecated',
+                          PyGIDeprecationWarning, stacklevel=2)
         return _gi._gvalue_get(self)
 
     def set_value(self, py_value):
diff --git a/tests/test_overrides_gobject.py b/tests/test_overrides_gobject.py
index 37292dbb..56a62f13 100644
--- a/tests/test_overrides_gobject.py
+++ b/tests/test_overrides_gobject.py
@@ -266,3 +266,11 @@ def test_value_uchar():
 
     with pytest.raises(OverflowError):
         v.set_value(256)
+
+
+def test_value_set_boxed_deprecate_non_boxed():
+    v = GObject.Value(GObject.TYPE_POINTER)
+    with pytest.warns(PyGIDeprecationWarning):
+        v.get_boxed()
+    with pytest.warns(PyGIDeprecationWarning):
+        v.set_boxed(None)


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