Login | Register For Free | Help
Search for: (Advanced)

Mailing List Archive: Python: Dev

no tp_traverse for dict iters

 

 

Python dev RSS feed   Index | Next | Previous | View Threaded


robert.schuppenies at gmail

Aug 25, 2008, 1:32 AM

Post #1 of 4 (725 views)
Permalink
no tp_traverse for dict iters

Hi.

Could you please explain to me why some iterators have a tp_traverse
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 get_referents function.

>>> t = (1,2,3)
>>> gc.get_referents(iter(t))
[(1, 2, 3)]
>>> s = set([1,2,3])
>>> gc.get_referents(iter(s))
[]
>>> d = {1:1, 2:2}
>>> gc.get_referents(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'?

thanks,
robert



_______________________________________________
Python-Dev mailing list
Python-Dev[at]python.org
http://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: http://mail.python.org/mailman/options/python-dev/list-python-dev%40lists.gossamer-threads.com


amauryfa at gmail

Aug 25, 2008, 4:22 AM

Post #2 of 4 (671 views)
Permalink
Re: no tp_traverse for dict iters [In reply to]

Hello,

2008/8/25 Robert Schuppenies <robert.schuppenies[at]gmail.com>:
> Hi.
>
> Could you please explain to me why some iterators have a tp_traverse
> 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 get_referents function.
>
>>>> t = (1,2,3)
>>>> gc.get_referents(iter(t))
> [(1, 2, 3)]
>>>> s = set([1,2,3])
>>>> gc.get_referents(iter(s))
> []
>>>> d = {1:1, 2:2}
>>>> gc.get_referents(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
Attachments: cycle.py (0.72 KB)


robert.schuppenies at gmail

Aug 25, 2008, 1:49 PM

Post #3 of 4 (671 views)
Permalink
Re: no tp_traverse for dict iters [In reply to]

Created bug report at http://bugs.python.org/issue3546.

Amaury Forgeot d'Arc wrote:
> 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.

_______________________________________________
Python-Dev mailing list
Python-Dev[at]python.org
http://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: http://mail.python.org/mailman/options/python-dev/list-python-dev%40lists.gossamer-threads.com


robert.schuppenies at gmail

Aug 25, 2008, 2:09 PM

Post #4 of 4 (670 views)
Permalink
Re: no tp_traverse for dict iters [In reply to]

Sry, wrong link. I meant http://bugs.python.org/issue3680.

Robert Schuppenies wrote:
> Created bug report at http://bugs.python.org/issue3546.
>
> Amaury Forgeot d'Arc wrote:
>> 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.

_______________________________________________
Python-Dev mailing list
Python-Dev[at]python.org
http://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: http://mail.python.org/mailman/options/python-dev/list-python-dev%40lists.gossamer-threads.com

Python dev RSS feed   Index | Next | Previous | View Threaded
 
 


Interested in having your list archived? Contact lists@gossamer-threads.com
 
  Web Applications & Managed Hosting Powered by Gossamer Threads Inc.