Commit 6c69fc7b authored by Christoph Reiter's avatar Christoph Reiter 🐍

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.
parent 48f80f8b
......@@ -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:
......
......@@ -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())
......
......@@ -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
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment