[New-bugs-announce] [issue30322] PyObject_GetIter does not behave as documented on dict objects
Sam De Meyer
report at bugs.python.org
Tue May 9 16:19:39 EDT 2017
New submission from Sam De Meyer:
According to the docs (https://docs.python.org/3/c-api/object.html) the `PyObject_GetIter` method should be equivalent to the python call `iter(<some_dict>)`, but, when given a dict, the `PyObject_GetIter` returns an iterator over key-value pairs whereas the `iter()` method returns an iterator over keys only.
I tripped over this when giving the `<some_dict>.update()` a dict-like object that does not inherit from the builtin dict and implements its own `__iter__()`.
The `update()` method eventually reaches the following piece of code:
> it = PyObject_GetIter(seq2);
> item = PyIter_Next(it);
> fast = PySequence_Fast(item, "");
> key = PySequence_Fast_GET_ITEM(fast, 0);
> value = PySequence_Fast_GET_ITEM(fast, 1);
displaying the difference in behaviour between `PyObject_GetIter` and `iter(o)`.
assignee: docs at python
nosy: Sam De Meyer, docs at python
title: PyObject_GetIter does not behave as documented on dict objects
versions: Python 3.6
Python tracker <report at bugs.python.org>
More information about the New-bugs-announce