New submission from Matteo Dell'Amico <de...@linux.it>:

The current MutableSet.__iand__ implementation calls self.discard while
iterating on self. This creates strange problems while implementing
MutableSet with simple choices. For example, consider the attached file
which implements set by delegating either to a set or a list. In the
first cases, an exception is raised; in the second, the result is not
what is expected.

Python 2.6+ (r26:66714, Oct 22 2008, 09:21:39) 
[GCC 4.3.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> from simpleset import WithSet, WithList
>>> s = WithSet([1,2])
>>> s &= ()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib/python2.6/_abcoll.py", line 290, in __iand__
    for value in self:
RuntimeError: Set changed size during iteration
>>> s = WithList([1,2])
>>> s &= ()
>>> list(s)
[2]

----------
components: Library (Lib)
files: simpleset.py
messages: 85006
nosy: della
severity: normal
status: open
title: MutableSet.__iand__ implementation calls self.discard while iterating on 
self
versions: Python 2.6, Python 2.7, Python 3.0, Python 3.1
Added file: http://bugs.python.org/file13538/simpleset.py

_______________________________________
Python tracker <rep...@bugs.python.org>
<http://bugs.python.org/issue5647>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to