[pygobject] variant: fix __bool__ for maybe types
- From: Christoph Reiter <creiter src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [pygobject] variant: fix __bool__ for maybe types
- Date: Wed, 21 Nov 2018 22:44:31 +0000 (UTC)
commit 9803907e48672b6b16ab16ec864b1df0375bc4f6
Author: Christoph Reiter <reiter christoph gmail com>
Date: Wed Nov 21 23:22:18 2018 +0100
variant: fix __bool__ for maybe types
For other types it is equal to bool of the unpacked type.
Do the same for maybe types.
gi/overrides/GLib.py | 7 ++-----
tests/test_overrides_glib.py | 8 +++++---
2 files changed, 7 insertions(+), 8 deletions(-)
---
diff --git a/gi/overrides/GLib.py b/gi/overrides/GLib.py
index 650d6bd8..e0ac233c 100644
--- a/gi/overrides/GLib.py
+++ b/gi/overrides/GLib.py
@@ -384,11 +384,8 @@ class Variant(GLib.Variant):
# Array, dict, tuple
if self.get_type_string().startswith('a') or self.get_type_string().startswith('('):
return self.n_children() != 0
- if self.get_type_string() in ['v']:
- # unpack works recursively, hence bool also works recursively
- return bool(self.unpack())
- # Everything else is True
- return True
+ # unpack works recursively, hence bool also works recursively
+ return bool(self.unpack())
def keys(self):
if not self.get_type_string().startswith('a{'):
diff --git a/tests/test_overrides_glib.py b/tests/test_overrides_glib.py
index 82a2608d..ac19ccd9 100644
--- a/tests/test_overrides_glib.py
+++ b/tests/test_overrides_glib.py
@@ -316,9 +316,6 @@ class TestGVariant(unittest.TestCase):
element = array.get_child_value(2)
self.assertEqual(element.n_children(), 0)
- variant = GLib.Variant('mai', None)
- assert bool(variant)
-
def test_create_complex(self):
variant = GLib.Variant('(as)', ([],))
self.assertEqual(variant.get_type_string(), '(as)')
@@ -663,6 +660,11 @@ class TestGVariant(unittest.TestCase):
assert_equals_bool('v', GLib.Variant('i', 0))
assert_equals_bool('v', GLib.Variant('i', 1))
+ # maybe types
+ assert_equals_bool('mi', 42)
+ assert_equals_bool('mi', 0)
+ assert_equals_bool('mi', None)
+
def test_repr(self):
# with C constructor
v = GLib.Variant.new_uint32(42)
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]