[issue6017] Dict fails to notice addition and deletion of keys during iteration

2009-05-17 Thread Georg Brandl

Georg Brandl ge...@python.org added the comment:

OK, I now changed it to may raise ... or fail to iterate over all
entries in r72708.

--

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue6017
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue6017] Dict fails to notice addition and deletion of keys during iteration

2009-05-16 Thread Steven D'Aprano

Steven D'Aprano st...@pearwood.info added the comment:

I agree with Terry Reedy. I'm re-opening it as a documentation bug (if 
I can -- if I can't, I'll just request somebody who can do so).

--
components:  -Interpreter Core
status: closed - open

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue6017
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue6017] Dict fails to notice addition and deletion of keys during iteration

2009-05-16 Thread Georg Brandl

Georg Brandl ge...@python.org added the comment:

I don't think it would be better to change the documentation to will
raise a RuntimeError or result in undefined behavior.  It already tells
you not to do this strongly enough.

--
status: open - closed

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue6017
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue6017] Dict fails to notice addition and deletion of keys during iteration

2009-05-16 Thread R. David Murray

R. David Murray rdmur...@bitdance.com added the comment:

The precisionist in me insists that at a minimum 'will' should be changed
to 'may'.  Otherwise either the docs are lying or the implementation
has a bug.

Or perhaps we could add a footnote about the intentionally divergent
behavior of the CPython implementation?

(As Terry pointed out these docs may be used by other implementors as a
prescriptive guide, just as the language reference is.)

--
nosy: +r.david.murray

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue6017
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue6017] Dict fails to notice addition and deletion of keys during iteration

2009-05-16 Thread Steven D'Aprano

Steven D'Aprano st...@pearwood.info added the comment:

With respect Georg, given that the behaviour won't be changed, the 
documentation is simply *wrong*. It's not a matter of telling 
people don't do this -- somebody, somewhere, is going to rely on the 
documented behaviour. The docs make the clear promise that, and I 
quote, Using iteritems() while adding or deleting entries in the 
dictionary will raise a RuntimeError, but that's not what happens. 
The actual behaviour is undefined.

--

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue6017
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue6017] Dict fails to notice addition and deletion of keys during iteration

2009-05-16 Thread Georg Brandl

Georg Brandl ge...@python.org added the comment:

I wouldn't call it *wrong* as much as *not the whole truth*.  It is true
that if just one key is added or removed, a RuntimeError will be raised.
 There are probably lots of places in our docs where the whole truth
isn't told, but in a way that works if you do the sensible thing.

In this case I can neither see anyone relying on RuntimeError being
raised (except for dict's own test suite), nor an implementor looking
only at these docs, not the source, to implement one of Python's most
crucial object types.

Anyway, if you find a new wording that isn't too clumsy, I'll change it.

--

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue6017
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue6017] Dict fails to notice addition and deletion of keys during iteration

2009-05-16 Thread Terry J. Reedy

Terry J. Reedy tjre...@udel.edu added the comment:

I would be happy enough to change 'will' to 'may'.  There are a lot of
undocumented exception-raising circumstances, and this one already be
undocumented in Py3.

--

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue6017
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue6017] Dict fails to notice addition and deletion of keys during iteration

2009-05-15 Thread Terry J. Reedy

Terry J. Reedy tjre...@udel.edu added the comment:

The OP reported a real mismatch between doc and behavior.  If the
behavior is not changed, I think the doc should be.  Other implementors,
reading the doc, might think that they do have to write code to track
changes.  From the doc, I thought that CPython did that.

So I suggest changing reopening and changing the doc to say
Changing the net size of the dictionary while using iteritems() will
raise a RuntimeError.  Same for iterkeys() and itervalues()[sp?]

Or remove the warning, as happened in the Py3 changeover to views, or
was that a mistake?

--
nosy: +tjreedy

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue6017
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue6017] Dict fails to notice addition and deletion of keys during iteration

2009-05-14 Thread Benjamin Peterson

Benjamin Peterson benja...@python.org added the comment:

This is correct; dict iterators check to see if the size of the dict is
different. However, fixing this problem would require tracking dict
contents during iteration. That strikes me as too inefficient and too
much code for this little case.

--
nosy: +benjamin.peterson
resolution:  - wont fix
status: open - closed

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue6017
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue6017] Dict fails to notice addition and deletion of keys during iteration

2009-05-13 Thread Steven D'Aprano

New submission from Steven D'Aprano st...@pearwood.info:

I'm not sure if this is a documentation bug or a behaviour bug, or 
possibly both.

The documentation warns about adding or deleting items from a dict 
while iterating over it:

Using iteritems() while adding or deleting entries in the dictionary 
will raise a RuntimeError.

http://docs.python.org/library/stdtypes.html#dict.iteritems

Same for other dict iterators.

However, you can add and delete items, so long as the overall size of 
the dict doesn't change. Consequently, some modifications to the dict 
aren't caught, leading to various misbehaviour in (at least) Python 
2.5 and 2.6.

Some dicts appear to run too long:

 d = dict(x=3, y=4)  # Two items
 it = d.iteritems()
 it.next()  # One
('y', 4)
 del d['y']
 d['z'] = 5
 it.next()  # Two
('x', 3)
 it.next()  # Three
('z', 5)


While others run too short:

 d = {-1: 'aa', -2: 'bb'}  # Two items
 it = d.iteritems()
 it.next()  # One
(-2, 'bb')
 del d[-1]
 d[0] = 'cc'
 it.next()
Traceback (most recent call last):
  File stdin, line 1, in module
StopIteration

--
assignee: georg.brandl
components: Documentation, Interpreter Core
messages: 87729
nosy: georg.brandl, stevenjd
severity: normal
status: open
title: Dict fails to notice addition and deletion of keys during iteration
type: behavior
versions: Python 2.5, Python 2.6

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue6017
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com