Fix T94121: PyAPI: ID property group returns wrong type with iter()

Regression in 265d97556a.
Where iterating directly on a property group failed, e.g.:
`iter(group)`, tests missed this since only `group.keys()`
was checked.
This commit is contained in:
Campbell Barton 2022-03-11 10:08:25 +11:00
parent 4a8bd31825
commit 27fb63381e
Notes: blender-bot 2023-02-14 09:24:53 +01:00
Referenced by issue #96241, 3.1: Potential candidates for corrective releases
Referenced by issue #94121, PyAPI: ID property group returns wrong type with iter()
2 changed files with 18 additions and 1 deletions

View File

@ -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)

View File

@ -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"]