[Python-Dev] Bug or not? Different behaviour iterating list and collections.deque (original) (raw)

Christos Georgiou tzot at mediconsa.com
Mon Jan 8 10:29:48 CET 2007


""Martin v. Löwis"" <martin at v.loewis.de> wrote in message news:45A19243.2000109 at v.loewis.de...

Christos Georgiou schrieb:

Is that intentional? It would have helped if you had said what "that" is you are referring to, it would also have helped if you had stated an opinion on whether you believe that to be a bug. For example, I think I would have phrased your post like this:

Yes, you are correct: I see now that I was too cryptic, but being cryptic was not my intention; instead, I wanted to avoid a discussion on the issue of the algorithm, which I didn't manage to avoid, so obviously my terseness was mistaken. I should be clear from the start.

In retrospection, the example code I chose, although it showed the two issues I thought important ('list / deque iteration discrepancy' and 'empty / non-empty deque iteration discrepancy') was not as plain as needed, since it gave to Josiah, at least, the impression that the matter was about list / deque merging.

""" If I apply .next() to an iter of a deque that has been modified, I get a RuntimeError:

py> d=collections.deque() py> d.append(10) py> i=iter(d) py> d.append(10) py> i.next() Traceback (most recent call last): File "", line 1, in ? RuntimeError: deque mutated during iteration Yet when I apply .next() to an iter of an initially-empty deque, I get StopIteration: py> d=collections.deque() py> i=iter(d) py> d.append(10) py> i.next() Traceback (most recent call last): File "", line 1, in ? StopIteration Is this a bug? Shouldn't the second example also raise the RuntimeError as the deque has been modified? (also, is appending an element a modification or a mutation?) """ To this question (.next on an iterator of a modified deque), my answer would be: "yes, that is a bug".

Yes. This behaviour was meant to be shown with the 'special_case' check. I will open a bug for this.

However, I feel you are referring to a different issue, unfortunately, I cannot tell from your post what that issue is.

No, you managed to capture large part of the essence of what I was saying, but again, this was not your responsibility, but mine. I should be more explicit.

Thank you.



More information about the Python-Dev mailing list