[pygobject/set-value-unify: 2/3] Value.set_value: allow None for TYPE_STRING
- From: Christoph Reiter <creiter src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [pygobject/set-value-unify: 2/3] Value.set_value: allow None for TYPE_STRING
- Date: Sat, 19 Jan 2019 13:38:19 +0000 (UTC)
commit b66e964ec1b27d5786d2e2276d18764df6a06e6c
Author: Christoph Reiter <reiter christoph gmail com>
Date: Sat Jan 19 13:43:28 2019 +0100
Value.set_value: allow None for TYPE_STRING
set_string() allows it too
gi/overrides/GObject.py | 4 ++--
tests/test_overrides_gobject.py | 4 ++--
2 files changed, 4 insertions(+), 4 deletions(-)
---
diff --git a/gi/overrides/GObject.py b/gi/overrides/GObject.py
index 04b5be65..20a92b0e 100644
--- a/gi/overrides/GObject.py
+++ b/gi/overrides/GObject.py
@@ -258,8 +258,8 @@ class Value(GObjectModule.Value):
elif gtype == TYPE_DOUBLE:
self.set_double(py_value)
elif gtype == TYPE_STRING:
- if isinstance(py_value, str):
- py_value = str(py_value)
+ if py_value is None or isinstance(py_value, str):
+ py_value = py_value
elif PY2:
if isinstance(py_value, text_type):
py_value = py_value.encode('UTF-8')
diff --git a/tests/test_overrides_gobject.py b/tests/test_overrides_gobject.py
index 47759b41..e62a27fd 100644
--- a/tests/test_overrides_gobject.py
+++ b/tests/test_overrides_gobject.py
@@ -222,8 +222,8 @@ def test_value_string():
assert v.get_value() == u"quux"
assert isinstance(v.get_value(), str)
- with pytest.raises(TypeError):
- v.set_value(None)
+ v.set_value(None)
+ assert v.get_value() is None
def test_value_pyobject():
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]