[pygobject] Gio.Settings: implement __iter__
- From: Christoph Reiter <creiter src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [pygobject] Gio.Settings: implement __iter__
- Date: Tue, 17 Apr 2018 11:08:01 +0000 (UTC)
commit c1da8edf4d18b6a1fa17ca55f4163af44ea95bbb
Author: Christoph Reiter <reiter christoph gmail com>
Date: Tue Apr 17 12:24:11 2018 +0200
Gio.Settings: implement __iter__
It defaults to __len__ and __getitem__ otherwise which fails because
we work with keys and not indices.
gi/overrides/Gio.py | 4 ++++
tests/test_gio.py | 5 +++++
2 files changed, 9 insertions(+)
---
diff --git a/gi/overrides/Gio.py b/gi/overrides/Gio.py
index 8604d550..3cdc7b18 100644
--- a/gi/overrides/Gio.py
+++ b/gi/overrides/Gio.py
@@ -105,6 +105,10 @@ class Settings(Gio.Settings):
def __len__(self):
return len(self.list_keys())
+ def __iter__(self):
+ for key in self.list_keys():
+ yield key
+
def __bool__(self):
# for "if mysettings" we don't want a dictionary-like test here, just
# if the object isn't None
diff --git a/tests/test_gio.py b/tests/test_gio.py
index 92159c17..6ad5b116 100644
--- a/tests/test_gio.py
+++ b/tests/test_gio.py
@@ -64,6 +64,11 @@ class TestGSettings(unittest.TestCase):
self.settings.reset('test-boolean')
self.settings.reset('test-enum')
+ def test_iter(self):
+ assert list(self.settings) == [
+ 'test-tuple', 'test-array', 'test-boolean', 'test-string',
+ 'test-enum']
+
def test_native(self):
self.assertTrue('test-array' in self.settings.list_keys())
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]