Raymond Hettinger wrote: > Pardon, I bungled the terminology. PySet_Next returns a borrowed > reference. That is problematic is arbitrary Python code can be run > afterwards (such as PyObject_Hash in the example).
Not really. It is under the control of the caller of PySet_Next what (if any) Python code is invoked, and getting this correct is straight-forward (once you know that it yields borrowed references). I don't know what specific application Barry has in mind, but I'm sure he can get it right (although it might be an interesting experiment to test that theory :-) In general, I would expect that people find it easier to get code involving PyDict_Next right than code dealing with iterators - primarily because of the error cases you have to consider. > We have a perfectly good way to iterate with PyIter_Next(). It may take > a couple of extra lines, but it is easy to get correct and has no > surprises. It seems that the only issue is that Barry says that he > refuses to use the iterator protocol. Heck, just turn it into a list > and index directly. There is no need to muck-up the set api for this. I don't care that much either way, although I would prefer to see an actual, current use case for PySet_Next, rather than theoretical, made-up examples. I don't expect to use Python sets in C code at all, personally. Regards, Martin _______________________________________________ Python-Dev mailing list Python-Dev@python.org http://mail.python.org/mailman/listinfo/python-dev Unsubscribe: http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com