[pygobject/set-value-unify: 1/3] basic: allow None for boolean parameters
- From: Christoph Reiter <creiter src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [pygobject/set-value-unify: 1/3] basic: allow None for boolean parameters
- Date: Sat, 19 Jan 2019 13:38:14 +0000 (UTC)
commit 6c69fc7b582ec1fd3faef4de3fade9a0cb7f8c05
Author: Christoph Reiter <reiter christoph gmail com>
Date: Sat Jan 19 11:31:41 2019 +0100
basic: allow None for boolean parameters
It already allows everything which can be passed to bool() except None.
I don't see a good reason for that so allow None as well.
gi/pygi-basictype.c | 2 ++
tests/test_gi.py | 5 +++++
tests/test_overrides_gobject.py | 5 +++--
3 files changed, 10 insertions(+), 2 deletions(-)
---
diff --git a/gi/pygi-basictype.c b/gi/pygi-basictype.c
index dafddf27..c0e5d1d0 100644
--- a/gi/pygi-basictype.c
+++ b/gi/pygi-basictype.c
@@ -1342,6 +1342,8 @@ arg_basic_type_setup_from_info (PyGIArgCache *arg_cache,
break;
case GI_TYPE_TAG_BOOLEAN:
+ arg_cache->allow_none = TRUE;
+ /* fall through */
case GI_TYPE_TAG_INT8:
case GI_TYPE_TAG_UINT8:
case GI_TYPE_TAG_INT16:
diff --git a/tests/test_gi.py b/tests/test_gi.py
index 2b6f3c0a..61ad4f18 100644
--- a/tests/test_gi.py
+++ b/tests/test_gi.py
@@ -87,6 +87,11 @@ class TestBoolean(unittest.TestCase):
GIMarshallingTests.boolean_in_true(1)
GIMarshallingTests.boolean_in_false(0)
+ def test_boolean_in_other_types(self):
+ GIMarshallingTests.boolean_in_true([""])
+ GIMarshallingTests.boolean_in_false([])
+ GIMarshallingTests.boolean_in_false(None)
+
def test_boolean_out(self):
self.assertEqual(True, GIMarshallingTests.boolean_out_true())
self.assertEqual(False, GIMarshallingTests.boolean_out_false())
diff --git a/tests/test_overrides_gobject.py b/tests/test_overrides_gobject.py
index 5c157f0e..47759b41 100644
--- a/tests/test_overrides_gobject.py
+++ b/tests/test_overrides_gobject.py
@@ -298,5 +298,6 @@ def test_value_boolean():
assert v.get_value() is False
v.set_value(["foo"])
assert v.get_value() is True
- with pytest.raises(TypeError):
- v.set_value(None)
+
+ v.set_value(None)
+ assert v.get_value() is False
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]