Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCampbell Barton <campbell@blender.org>2022-03-11 02:08:25 +0300
committerPhilipp Oeser <info@graphics-engineer.com>2022-03-21 14:44:59 +0300
commit2b8d778a68b53d63d8c897d5150951ecaecc6dc8 (patch)
treeccdbdbeee539e567a7202cb85563e269ff004084
parenteff7e9aa45af32b7de7893c43aa14c933c9d270c (diff)
Fix T94121: PyAPI: ID property group returns wrong type with iter()
Regression in 265d97556aa0f0f2a0e4dd7584e3b8573bbddd54. Where iterating directly on a property group failed, e.g.: `iter(group)`, tests missed this since only `group.keys()` was checked.
-rw-r--r--source/blender/python/generic/idprop_py_api.c11
-rw-r--r--tests/python/bl_pyapi_idprop.py8
2 files changed, 18 insertions, 1 deletions
diff --git a/source/blender/python/generic/idprop_py_api.c b/source/blender/python/generic/idprop_py_api.c
index 0a870102b6f..a839786cce8 100644
--- a/source/blender/python/generic/idprop_py_api.c
+++ b/source/blender/python/generic/idprop_py_api.c
@@ -770,7 +770,16 @@ static int BPy_IDGroup_Map_SetItem(BPy_IDProperty *self, PyObject *key, PyObject
static PyObject *BPy_IDGroup_iter(BPy_IDProperty *self)
{
- return BPy_IDGroup_ViewKeys_CreatePyObject(self);
+ PyObject *iterable = BPy_IDGroup_ViewKeys_CreatePyObject(self);
+ PyObject *ret;
+ if (iterable) {
+ ret = PyObject_GetIter(iterable);
+ Py_DECREF(iterable);
+ }
+ else {
+ ret = NULL;
+ }
+ return ret;
}
PyObject *BPy_IDGroup_MapDataToPy(IDProperty *prop)
diff --git a/tests/python/bl_pyapi_idprop.py b/tests/python/bl_pyapi_idprop.py
index 4cee39fafb0..e9056137bcf 100644
--- a/tests/python/bl_pyapi_idprop.py
+++ b/tests/python/bl_pyapi_idprop.py
@@ -172,6 +172,14 @@ class TestIdPropertyGroupView(TestHelper, unittest.TestCase):
self.assertEqual(list(self.id.items()), [(k, v) for v, k in enumerate(text)])
self.assertEqual(list(reversed(self.id.items())), list(reversed([(k, v) for v, k in enumerate(text)])))
+ # Check direct iteration is working as expected.
+ self.id["group"] = {ch: i for i, ch in enumerate(text)}
+ group = self.id["group"]
+
+ self.assertEqual(len(group), len(text))
+ self.assertEqual(list(iter(group)), text)
+
+
def test_contains(self):
# Check `idprop.types.IDPropertyGroupView{Keys/Values/Items}.__contains__`
text = ["A", "B", "C"]