[Python-Dev] no tp_traverse for dict iters (original) (raw)

Amaury Forgeot d'Arc amauryfa at gmail.com
Mon Aug 25 13:22:10 CEST 2008


Hello,

2008/8/25 Robert Schuppenies <robert.schuppenies at gmail.com>:

Hi.

Could you please explain to me why some iterators have a tptraverse implementation and others do not? For example tupleiterator has one, but none of the dict iterators. Same for set iterators (and possibly others). It shows in Python when you use the getreferents function.

t = (1,2,3) gc.getreferents(iter(t)) [(1, 2, 3)] s = set([1,2,3]) gc.getreferents(iter(s)) [] d = {1:1, 2:2} gc.getreferents(iter(d)) [] And is it correct that you can rephrase the question to 'why some iterators are seen as container objects and others are not'?

Yes, this can lead to some object cycle that are not collected. See the attached script: a cycle involving a list iterator is collected by the garbage collector, but a cycle with a dict iterator is not. This is worth a bug report IMO.

-- Amaury Forgeot d'Arc -------------- next part -------------- A non-text attachment was scrubbed... Name: cycle.py Type: text/x-python Size: 740 bytes Desc: not available URL: <http://mail.python.org/pipermail/python-dev/attachments/20080825/bc93b24a/attachment.py>



More information about the Python-Dev mailing list