[Bf-blender-cvs] [27fb63381e9] master: Fix T94121: PyAPI: ID property group returns wrong type with iter()
Campbell Barton
noreply at git.blender.org
Fri Mar 11 00:27:06 CET 2022
Commit: 27fb63381e9b0963976237c58ca2cfc9bc5ddfd8
Author: Campbell Barton
Date: Fri Mar 11 10:08:25 2022 +1100
Branches: master
https://developer.blender.org/rB27fb63381e9b0963976237c58ca2cfc9bc5ddfd8
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.
===================================================================
M source/blender/python/generic/idprop_py_api.c
M tests/python/bl_pyapi_idprop.py
===================================================================
diff --git a/source/blender/python/generic/idprop_py_api.c b/source/blender/python/generic/idprop_py_api.c
index c05c003b176..2fbb6b8ee05 100644
--- a/source/blender/python/generic/idprop_py_api.c
+++ b/source/blender/python/generic/idprop_py_api.c
@@ -756,7 +756,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 0e93ba0b690..ac1bd618570 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"]
More information about the Bf-blender-cvs
mailing list