This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author Sam De Meyer
Recipients Sam De Meyer, docs@python
Date 2017-05-09.20:19:39
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1494361179.47.0.337252878474.issue30322@psf.upfronthosting.co.za>
In-reply-to
Content
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:
https://hg.python.org/cpython/file/4243df51fe43/Objects/dictobject.c#l2383

>    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)`.
History
Date User Action Args
2017-05-09 20:19:39Sam De Meyersetrecipients: + Sam De Meyer, docs@python
2017-05-09 20:19:39Sam De Meyersetmessageid: <1494361179.47.0.337252878474.issue30322@psf.upfronthosting.co.za>
2017-05-09 20:19:39Sam De Meyerlinkissue30322 messages
2017-05-09 20:19:39Sam De Meyercreate